I've a native android app (NativeActivity
, no java code but only libMyApp.so
native library)
The app runs perfectly on Android 5.0.1 and 5.1.1 but crashes on android 4.3 and 4.2.2
For 5.0.1 and 5.1.1 versions load the .so
lib successfully from
/data/data/com.example.myapp/lib/libMyApp.so
4.3 and 4.2.2 versions try to load from one of following locations
/data/app-lib/com.example.myapp-1/libMyApp.so
/data/app-lib/com.example.myapp-2/libMyApp.so
The error message is
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.example.myapp-2/libMyApp.so
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method
My app has a single shared library i.e. doesn't depend on third party libs.
And the module name is specified in manifest file like this
<meta-data android:name="android.app.lib_name"
android:value="MyApp" />
The libMyApp.so
is linked with -llog -lGLESv3 -lGLESv2 -lGLESv1_CM -lEGL -landroid -lz
libs.
Why the lib cannot be loaded, what I'm missing ?
Why old android versions do not load from /data/data/com.example.myapp/lib/
?!
Does the older android versions have another module naming convention ?
After 2 days of research I finally managed to find the source of issue.
Firstly somehow Native App doesn't show full linker error in logcat - (I don't know why!)
But after converting the same app to Java/JNI app, I was able to see following linker error only on Android versions prior to L (5.*).
dlopen("/data/app-lib/com.example.myapp/libMyApp.so") failed: dlopen failed: cannot locate symbol "srand" referenced by "libMyApp.so"...
I used to compile the cpp code with android-21 api level from r10e ndk.
Which basically doesn't guarantee that the app will run OK on android version prior to L.
Here is the official android bug report .
As in my native app OGLES3.1
features are used, I cannot downgrade the target SDK level from 21, so I had no choice than updating min sdk level to 21.