Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app crash after NDK upgraded from 20.1 to 21.0

I was using Android Studio to create an app using Java, Kotlin and C++.

Yesterday, I upgraded the Android NDK from version 20.1 to version 21.0, and then the android studio keeps crash if I connect to my android phone and run.

The piece of crash log in Logcat is as below.

    --------- beginning of crash
2020-01-17 15:46:15.737 13606-13606/com.blinkai.Video_2020_Debugging E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.blinkai.Video_2020_Debugging, PID: 13606
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libomp.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
        at java.lang.System.loadLibrary(System.java:1667)
        at com.blinkai.blinkai.MainActivity.<clinit>(MainActivity.kt:395)
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
        at android.support.v4.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:43)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3328)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)

The code in MainActivity.kt:395 is:

// Used to load the 'native-lib' library on application startup.
init {
  System.loadLibrary("native-lib")
}

Thank you very much for your help!

like image 250
Xiaorui Ma Avatar asked Dec 13 '22 09:12

Xiaorui Ma


1 Answers

https://github.com/android/ndk/issues/1028

That problem mentioned in ndk repo. They suggests to use flag -static-openmp.

I put the flag in my CMakeLists.txt like:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp -static-openmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -static-openmp")

and that's do the job.

like image 60
gordinmitya Avatar answered Dec 15 '22 23:12

gordinmitya