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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With