Reputation: 23
I've been battling to get Cpp programs on Android for a few days now, and I've ran into a problem what I think might be a bug. I'm using SDL2 but no other libraries, also I'm using the SDL android project template.
Basic programs run fine, but I would want to use Cpp stdlibs and STL, so according to instructions, I added APP_STL := stlport_static to Application.mk and rebuilt the program but after this the app just shows a blank screen for a while and then crashes, debug says following:
01-20 22:10:14.817: D/dalvikvm(26097): Trying to load lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d06890
01-20 22:10:14.817: W/dalvikvm(26097): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/libsdl/app/SDLActivity;
01-20 22:10:14.817: W/dalvikvm(26097): Class init failed in newInstance call (Lcom/kebabkeisari/peli/Ribale;)
01-20 22:10:14.822: D/AndroidRuntime(26097): Shutting down VM
01-20 22:10:14.822: W/dalvikvm(26097): threadid=1: thread exiting with uncaught exception (group=0x4109f2a0)
01-20 22:10:14.827: E/AndroidRuntime(26097): FATAL EXCEPTION: main
01-20 22:10:14.827: E/AndroidRuntime(26097): java.lang.ExceptionInInitializerError
01-20 22:10:14.827: E/AndroidRuntime(26097): at java.lang.Class.newInstanceImpl(Native Method)
01-20 22:10:14.827: E/AndroidRuntime(26097): at java.lang.Class.newInstance(Class.java:1319)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.os.Looper.loop(Looper.java:137)
01-20 22:10:14.827: E/AndroidRuntime(26097): at android.app.ActivityThread.main(ActivityThread.java:4898)
01-20 22:10:14.827: E/AndroidRuntime(26097): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 22:10:14.827: E/AndroidRuntime(26097): at java.lang.reflect.Method.invoke(Method.java:511)
01-20 22:10:14.827: E/AndroidRuntime(26097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-20 22:10:14.827: E/AndroidRuntime(26097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-20 22:10:14.827: E/AndroidRuntime(26097): at dalvik.system.NativeStart.main(Native Method)
01-20 22:10:14.827: E/AndroidRuntime(26097): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1307]: 1951 cannot locate 'signal'...
01-20 22:10:14.827: E/AndroidRuntime(26097): at java.lang.Runtime.loadLibrary(Runtime.java:370)
01-20 22:10:14.827: E/AndroidRuntime(26097): at java.lang.System.loadLibrary(System.java:535)
01-20 22:10:14.827: E/AndroidRuntime(26097): at org.libsdl.app.SDLActivity.<clinit>(SDLActivity.java:49)
01-20 22:10:14.827: E/AndroidRuntime(26097): ... 15 more
So the program fails linking at runtime. STL is the culprit and yes, I have tried gnustl and others but the same problem occurs.
I'm using ndk-build and Eclipse, running apps on Samsung Galaxy S3.
I searched the net and there's indeed a ton of similiar problems, one place said to not build into armeabi and armeabi-v7 at the same time, but that did not help.
Upvotes: 1
Views: 593
Reputation: 13317
This seems to be the same issue as a lot of other recent ones, like Cannot load library: reloc_library[1285]: cannot locate 'rand'. The issue is that you are building your app using the android-21
API. The signal
function (just like rand
) used to be an inline function in a header (redirecting the code to bsd_signal
and lrand48
respectively), but in android-21
new functions were added, so these are no longer inlines in the header.
Therefore, if you want your app to run on platforms earlier than android-21
, you need to make sure you build the native code using the lowest API level you want your code to run on, e.g. by adding APP_PLATFORM := android-9
in jni/Application.mk
.
If you need features from newer ones, android-19
should also work mostly pretty well. For verions prior to 21, newer platform versions only added new functions that didn't exist before (but the old functions behaved like before), so if you only are using functions that existed in android-N, it should work on android-N even if you built it with android-19
(for N < 19). But 21 changed all of this, functions that existed before (but redirected to other functions) now link to a different name (the more correct one to be honest), which wasn't available before.
This doesn't affect what API level you can build your java code (if any) with, though - you can still build that part targeting the latest API if you want to.
Upvotes: 5