Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 Android build

This thread is locked; no one can reply to it. rss feed Print
Allegro 5 Android build
kenmasters1976
Member #8,794
July 2007

I'm experimenting with Android and, after installing Android Studio, the Android SDK and NDK, the first thing I did was to build Allegro 5 following the instructions in the README_android.txt file. I setup a x86 toolchain to be able to test Allegro in the Android emulator and, after a few hurdles along the way, I managed to build Allegro successfully. However, I'm having trouble running the Allegro examples on the Android emulator.

First of all, the README_android.txt seems to be a bit outdated since there's no bin directory containing the final .apk; instead, the .apk files are generated in app/build/outputs/apk/debug, e.g.:
examples/ex_draw_bitmap.project/app/build/outputs/apk/debug/app-debug.apk instead of examples/ex_draw_bitmap.project/bin/ex_draw_bitmap-debug.apk.

I installed the .apk but even then attempting to run the app as instructed in README_android.txt returned an error:

generic_x86:/ $ am start -n org.liballeg.examples.ex_draw_bitmap/.Activity
Starting: Intent { cmp=org.liballeg.examples.ex_draw_bitmap/.Activity }
Error type 3
Error: Activity class {org.liballeg.examples.ex_draw_bitmap/org.liballeg.examples.ex_draw_bitmap.Activity} does not exist.

Seems like the README_android.txt file is outdated here again since apparently there's no such package installed:

generic_x86:/ $ pm list packages
...
package:org.liballeg.ex_draw_bitmap

But using org.liballeg.ex_draw_bitmap instead doesn't solve the issue:

generic_x86:/ $ am start -n org.liballeg.ex_draw_bitmap/.Activity
Starting: Intent { cmp=org.liballeg.ex_draw_bitmap/.Activity }
Error type 3
Error: Activity class {org.liballeg.ex_draw_bitmap/org.liballeg.ex_draw_bitmap.Activity} does not exist.

Using MainActivity as indicated in the manifest gives the same result. The application icon appears in the Android emulator but the application closes/crashes immediately after clicking on it. So at this point I'm lost.

Any help welcome. Thanks.

[EDIT:] Nevermind, using the binaries from the maven repository as described in the wiki worked.

[EDIT 2:] Sorry for bumping this but now the Allegro sample program using the binaries from the maven repository works fine on the Android emulator but crashes on a real tablet (an old cheap chinese tablet with Android 4.0.3).

D/AndroidRuntime( 2724): 
D/AndroidRuntime( 2724): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime( 2724): CheckJNI is OFF
D/AndroidRuntime( 2724): Calling main entry com.android.commands.am.Am
I/ActivityManager(  218): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.myfirstapplication/.MainActivity} from pid 2724
D/AndroidRuntime( 2724): Shutting down VM
I/AndroidRuntime( 2724): NOTE: attach of thread 'Binder Thread #3' failed
D/dalvikvm( 2724): GC_CONCURRENT freed 99K, 77% free 480K/2048K, paused 0ms+1ms
D/dalvikvm( 2735): Late-enabling CheckJNI
I/ActivityManager(  218): Start proc com.example.myfirstapplication for activity com.example.myfirstapplication/.MainActivity: pid=2735 uid=10065 gids={}
D/OpenGLRenderer(  638): Flushing caches (mode 1)
D/OpenGLRenderer(  638): Flushing caches (mode 0)
D/dalvikvm( 2735): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro.so 0x41066220
W/dalvikvm( 2735): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/myfirstapplication/MainActivity;
W/dalvikvm( 2735): Class init failed in newInstance call (Lcom/example/myfirstapplication/MainActivity;)
D/AndroidRuntime( 2735): Shutting down VM
W/dalvikvm( 2735): threadid=1: thread exiting with uncaught exception (group=0x409f61f8)
E/AndroidRuntime( 2735): FATAL EXCEPTION: main
E/AndroidRuntime( 2735): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 2735): 	at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 2735): 	at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime( 2735): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
E/AndroidRuntime( 2735): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
E/AndroidRuntime( 2735): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 2735): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 2735): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 2735): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2735): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2735): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 2735): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2735): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2735): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 2735): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 2735): 	at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2735): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    85 cannot locate 'stderr'...
E/AndroidRuntime( 2735): 
E/AndroidRuntime( 2735): 	at java.lang.Runtime.loadLibrary(Runtime.java:370)
E/AndroidRuntime( 2735): 	at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime( 2735): 	at com.example.myfirstapplication.MainActivity.<clinit>(MainActivity.java:7)
E/AndroidRuntime( 2735): 	... 15 more
W/ActivityManager(  218):   Force finishing activity com.example.myfirstapplication/.MainActivity
D/dalvikvm( 2735): GC_CONCURRENT freed 187K, 5% free 6825K/7111K, paused 2ms+1ms
D/dalvikvm(  218): GC_FOR_ALLOC freed 392K, 21% free 9869K/12423K, paused 82ms
W/ActivityManager(  218): Activity pause timeout for ActivityRecord{412587b8 com.example.myfirstapplication/.MainActivity}
W/ActivityManager(  218): Activity destroy timeout for ActivityRecord{412587b8 com.example.myfirstapplication/.MainActivity}
D/Zygote  (   85): Process 2735 terminated by signal (15)
I/ActivityManager(  218): Process com.example.myfirstapplication (pid 2735) has died.

Elias
Member #358
May 2000

Does it work in a 4.0.3 emulator? I'll try myself when I get a chance - as far as I remember I compiled with SDK 15 which happens to be exactly 4.0.3 as oldest supported version. I have not seen the missing stderr in reloc_library error myself - but usually things like that point to an API incompatibility.

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

Elias said:

usually things like that point to an API incompatibility

Yeah, I found some information suggesting that but the tablet reports SDK 15:

root@android:/ # cat /system/build.prop
# begin build properties
# autogenerated by buildinfo.sh
ro.build.id=IML74K
ro.build.display.id=20120302.180049
ro.build.version.incremental=20120228
ro.build.version.sdk=15
ro.build.version.codename=REL
ro.build.version.release=4.0.3
ro.build.date=Tue Feb 28 18:00:56 CST 2012
...

I will download a 4.0.3 emulator and report back.

[EDIT:] It took me a long time to get a 4.0.3 image running in the emulator. I was getting this:

{"name":"611676","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/b\/9bc9c1694e00d4bd40ec71f6e27f31f6.png","w":378,"h":584,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/b\/9bc9c1694e00d4bd40ec71f6e27f31f6"}611676

It seems to be a common issue with the 4.0.3 image from Android Studio with an apparently random solution. When I finally got it to work I tried running the Allegro example and got this:

I/ActivityManager( 1191): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.myfirstapplication/.MainActivity} from pid 1307
D/        ( 1191): HostConnection::get() New Host Connection established 0x9b680d8, tid 1225
D/dalvikvm( 1921): Not late-enabling CheckJNI (already on)
I/ActivityManager( 1191): Start proc com.example.myfirstapplication for activity com.example.myfirstapplication/.MainActivity: pid=1921 uid=10044 gids={}
W/NetworkManagementSocketTagger( 1191): setKernelCountSet(10044, 1) failed with errno -2
D/OpenGLRenderer( 1307): Flushing caches (mode 1)
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro.so 0xa08dc120
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_primitives.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_primitives.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_primitives.so 0xa08dc120, skipping init
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_image.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_image.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_image.so 0xa08dc120, skipping init
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_font.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_font.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_font.so 0xa08dc120, skipping init
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_ttf.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_ttf.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_ttf.so 0xa08dc120, skipping init
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_audio.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_audio.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_audio.so 0xa08dc120, skipping init
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_acodec.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_acodec.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_acodec.so 0xa08dc120, skipping init
D/dalvikvm( 1921): Trying to load lib /data/data/com.example.myfirstapplication/lib/liballegro_color.so 0xa08dc120
D/dalvikvm( 1921): Added shared lib /data/data/com.example.myfirstapplication/lib/liballegro_color.so 0xa08dc120
D/dalvikvm( 1921): No JNI_OnLoad found in /data/data/com.example.myfirstapplication/lib/liballegro_color.so 0xa08dc120, skipping init
D/AllegroActivity( 1921): Number of input devices: 2
D/AllegroActivity( 1921): onCreate
D/AllegroActivity( 1921): Files Dir: /data/data/com.example.myfirstapplication/files
D/AllegroActivity( 1921): External Storage Dir: /mnt/sdcard
W/ApplicationContext( 1921): Unable to create external files directory
D/AllegroActivity( 1921): External Files Dir: null
D/AllegroActivity( 1921): external: avail = false writable = false
D/AllegroActivity( 1921): sourceDir: /data/app/com.example.myfirstapplication-1.apk
D/AllegroActivity( 1921): publicSourceDir: /data/app/com.example.myfirstapplication-1.apk
D/AllegroActivity( 1921): before nativeOnCreate
D/dalvikvm( 1191): GC_FOR_ALLOC freed 1013K, 15% free 12659K/14791K, paused 9ms
D/AllegroActivity( 1921): nativeOnCreate failed
D/OpenGLRenderer( 1307): GL error from OpenGLRenderer: 0x506
D/dalvikvm( 1307): GC_FOR_ALLOC freed 2995K, 23% free 11941K/15495K, paused 3ms
D/dalvikvm( 1307): GC_CONCURRENT freed 38K, 18% free 12807K/15495K, paused 1ms+1ms
W/NetworkManagementSocketTagger( 1191): setKernelCountSet(10044, 0) failed with errno -2
D/AllegroActivity( 1921): onDestroy
W/InputManagerService( 1191): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@a0cf23a8
I/ActivityManager( 1191): Process com.example.myfirstapplication (pid 1921) has died.
D/dalvikvm( 1307): GC_CONCURRENT freed 1672K, 21% free 12286K/15495K, paused 0ms+1ms
D/dalvikvm( 1307): GC_FOR_ALLOC freed 105K, 20% free 12460K/15495K, paused 3ms
I/dalvikvm-heap( 1307): Grow heap (frag case) to 13.445MB for 1286220-byte allocation
D/dalvikvm( 1307): GC_FOR_ALLOC freed 22K, 12% free 13694K/15495K, paused 6ms
D/dalvikvm( 1307): GC_CONCURRENT freed <1K, 12% free 13694K/15495K, paused 0ms+0ms
D/gralloc_ranchu( 1191): gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
W/ActivityManager( 1191): Activity destroy timeout for ActivityRecord{a0cabb70 com.example.myfirstapplication/.MainActivity}

The error is different from the one I get in the real tablet but the application won't run in the Android 4.0.3 emulator either. Not knowing if the error was caused by the emulator issue in the first screenshot, I tried running the "Hello World" example from Android Studio and it worked as expected:

{"name":"611677","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/3\/431a30abfd4466ef852ab1bf7af794ea.png","w":378,"h":584,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/3\/431a30abfd4466ef852ab1bf7af794ea"}611677

So the problem remains with the Allegro program not running on Android 4.0.3 whether it is in the real tablet or in the emulator.

[EDIT 2:] Seeing that the error was on the nativeOnCreate() function, I rebuild the project with the debug version of Allegro and got this:

...
08-06 00:09:42.151 2101-2101/com.example.myfirstapplication D/AllegroActivity: External Files Dir: null
    external: avail = false writable = false
    sourceDir: /data/app/com.example.myfirstapplication-2.apk
    publicSourceDir: /data/app/com.example.myfirstapplication-2.apk
    before nativeOnCreate
08-06 00:09:42.161 2101-2101/com.example.myfirstapplication I/allegro: android  D 2101:     android_system.c:180  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] entered nativeOnCreate
    android  D 2101:     android_system.c:188  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] pthread_self:0xb7757c80
    android  D 2101:     android_system.c:189  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] nativeOnCreate begin
    android  D 2101:     android_system.c:193  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] grab activity global refs
08-06 00:09:42.171 2101-2101/com.example.myfirstapplication I/allegro: android  D 2101:     android_system.c:215  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] create mutex and cond objects
    android  D 2101:     android_system.c:219  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] get directories
    android  D 2101:     android_system.c:226  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] resources_dir: /data/data/com.example.myfirstapplication/files
    android  D 2101:     android_system.c:227  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] data_dir: /data/data/com.example.myfirstapplication/files
    android  D 2101:     android_system.c:228  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] apk_path: /data/app/com.example.myfirstapplication-2.apk
    android  D 2101:     android_system.c:229  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] model: Android SDK built for x86
    android  D 2101:     android_system.c:230  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] manufacturer: unknown
    android  D 2101:     android_system.c:232  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] creating ALLEGRO_SYSTEM_ANDROID struct
    android  D 2101:     android_system.c:236  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] get system pointer
    android  D 2101:     android_system.c:238  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] get system interface
    android  D 2101:     android_system.c:241  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] init display vector
    android  D 2101:     android_system.c:244  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] init time
    android  D 2101:     android_system.c:248  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] load user lib: libnative-lib.so
    android  E 2101:     android_system.c:251  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] failed to load user lib: libnative-lib.so
    android  E 2101:     android_system.c:252  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] Cannot load library: load_library[1091]: Library 'libnative-lib.so' not found
08-06 00:09:42.251 2101-2101/com.example.myfirstapplication D/AllegroActivity: nativeOnCreate failed
08-06 00:09:42.261 2101-2101/? D/AllegroActivity: onDestroy

So it seems it fails to load libnative-lib.so.

[EDIT 3:] Bumping to prevent the thread from locking. I've tried all kind of options -using the prebuilt binaries, building manually- always with the same result: the Allegro programs work -kinda- in the API 28 emulator but not in the real tablet nor in the API 15 emulator. Am I doing something wrong or is Android 4.0.3 no longer supported?.

As a side note, I've tried running the NDK samples and some of them work correctly on the Android 4.0.3 tablet while others report similar errors when loading native libraries (others simply require a higher API so they won't run on the 4.0.3 tablet).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

My current phone doesn't connect properly to my laptop. The drivers are faulty and no one ever bothers to update them on their end.

On a brighter note, I'm getting a new phone, and I want another Android. I liked my Motorola Droid Turbo 2 but as I said it doesn't work with my laptop. If I get a new phone here today maybe I can help test this.

Recommendations for a new phone? Android of course

Elias
Member #358
May 2000

D/AllegroActivity( 1921): nativeOnCreate failed

Can you make sure you are using a debug build? It seems your logcat only shows the unconditional Log.d lines, but none of the ALLEGRO_DEBUG. E.g. here is nativeOnCreate: https://github.com/liballeg/allegro5/blob/ec6c8f2dbba8ba93f215295b0ee60fe1750eb15b/src/android/android_system.c#L173

And you don't even get the initial "entered nativeOnCreate" log message. Knowing which of the errors inside of nativeOnCreate get triggered would help a lot.

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

The last log in my previous post was made with the debug build of Allegro, you can see the other debug messages except the one you mention. Maybe I accidentally omitted it when pasting the log. Anyway, here's a fresh, unfiltered log:

D/dalvikvm( 8863): Late-enabling CheckJNI
I/ActivityManager(  146): Start proc org.liballeg.speed for activity org.liballeg.speed/org.liballeg.app.MainActivity: pid=8863 uid=10067 gids={1015}
D/OpenGLRenderer(  337): Flushing caches (mode 1)
D/OpenGLRenderer(  337): Flushing caches (mode 0)
D/loadLibrary( 8863): allegro-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro-debug.so 0x41053aa8
D/loadLibrary( 8863): allegro_primitives-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_primitives-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_primitives-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_primitives-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_image-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_image-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_image-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_image-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_font-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_font-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_font-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_font-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_ttf-debug
D/loadLibrary( 8863): allegro_ttf
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_ttf.so 0x41053aa8
D/loadLibrary( 8863): allegro_ttf FAILED
D/loadLibrary( 8863): allegro_audio-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_audio-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_audio-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_audio-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_acodec-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_acodec-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_acodec-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_acodec-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_color-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_color-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_color-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_color-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_memfile-debug
D/dalvikvm( 8863): Trying to load lib /data/data/org.liballeg.speed/lib/liballegro_memfile-debug.so 0x41053aa8
D/dalvikvm( 8863): Added shared lib /data/data/org.liballeg.speed/lib/liballegro_memfile-debug.so 0x41053aa8
D/dalvikvm( 8863): No JNI_OnLoad found in /data/data/org.liballeg.speed/lib/liballegro_memfile-debug.so 0x41053aa8, skipping init
D/loadLibrary( 8863): allegro_physfs-debug
D/loadLibrary( 8863): allegro_physfs
D/loadLibrary( 8863): allegro_physfs FAILED
D/loadLibrary( 8863): allegro_video-debug
D/loadLibrary( 8863): allegro_video
D/loadLibrary( 8863): allegro_video FAILED
D/AllegroActivity( 8863): Number of input devices: 3
D/AllegroActivity( 8863): onCreate
D/AllegroActivity( 8863): Files Dir: /data/data/org.liballeg.speed/files
D/AllegroActivity( 8863): External Storage Dir: /mnt/sdcard
D/AllegroActivity( 8863): External Files Dir: /mnt/sdcard/Android/data/org.liballeg.speed/files
D/AllegroActivity( 8863): external: avail = true writable = true
D/AllegroActivity( 8863): sourceDir: /data/app/org.liballeg.speed-1.apk
D/AllegroActivity( 8863): publicSourceDir: /data/app/org.liballeg.speed-1.apk
D/AllegroActivity( 8863): before nativeOnCreate
I/allegro ( 8863): android  D 8863:     android_system.c:180  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] entered nativeOnCreate
I/allegro ( 8863): android  D 8863:     android_system.c:188  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] pthread_self:0x40097488
I/allegro ( 8863): android  D 8863:     android_system.c:189  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] nativeOnCreate begin
I/allegro ( 8863): android  D 8863:     android_system.c:193  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] grab activity global refs
I/allegro ( 8863): android  D 8863:     android_system.c:215  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] create mutex and cond objects
I/allegro ( 8863): android  D 8863:     android_system.c:219  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] get directories
I/allegro ( 8863): android  D 8863:     android_system.c:226  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] resources_dir: /data/data/org.liballeg.speed/files
I/allegro ( 8863): android  D 8863:     android_system.c:227  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] data_dir: /data/data/org.liballeg.speed/files
I/allegro ( 8863): android  D 8863:     android_system.c:228  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] apk_path: /data/app/org.liballeg.speed-1.apk
I/allegro ( 8863): android  D 8863:     android_system.c:229  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] model: novo7_ELF
I/allegro ( 8863): android  D 8863:     android_system.c:230  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] manufacturer: unknown
I/allegro ( 8863): android  D 8863:     android_system.c:232  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] creating ALLEGRO_SYSTEM_ANDROID struct
I/allegro ( 8863): android  D 8863:     android_system.c:236  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] get system pointer
I/allegro ( 8863): android  D 8863:     android_system.c:238  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] get system interface
I/allegro ( 8863): android  D 8863:     android_system.c:241  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] init display vector
I/allegro ( 8863): android  D 8863:     android_system.c:244  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] init time
I/allegro ( 8863): android  D 8863:     android_system.c:248  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] load user lib: libnative-lib.so
I/allegro ( 8863): android  E 8863:     android_system.c:251  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] failed to load user lib: libnative-lib.so
I/allegro ( 8863): android  E 8863:     android_system.c:252  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] Cannot load library: load_library[1091]: Library 'libnative-lib.so' not found
D/AllegroActivity( 8863): nativeOnCreate failed
W/InputManagerService(  146): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4131c428
D/AllegroActivity( 8863): onDestroy
I/ActivityManager(  146): Process org.liballeg.speed (pid 8863) has died.

The error always happens when trying to load libnative-lib.so.

Hopefully this weekend I will be able to borrow a phone/tablet to try on a different hardware or Android version.

Elias
Member #358
May 2000

Hm, can you check your .apk (it's just a .zip) and see if it has libnative-lib.so inside?

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

Yes, the file is in there. In fact, as I said before, the exact same .apk, built using the x86 toolchain, works in the API 28 emulator but not in the API 15 emulator.

Of course, for the real tablet I'm using the arm toolchain and there the app also fails when trying to load libnative-lib.so.

Elias
Member #358
May 2000

Which is probably due to that initial error you saw where "stderr" could not be found which the .so depends on - and I guess sometimes it just says "not found" instead of "dependencies missing". Anyway, not sure what to do - I don't have an actual 4.0.3 device anymore myself.

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

That error was present when using the prebuilt binaries from the maven repository which, I think, were built for a higher API; that's consistent with the information you can find about the error and also there's the fact that the python script uses -DANDROID_TARGET=android-26 when building Allegro.

So the prebuilt binaries are likely the cause of the stderr error when trying to use them on Android 4.0.3. It was only until I built Allegro manually with -DANDROID_TARGET=android-15 that the libnative-lib.so error appeared.

So, I guess the short answer is Allegro won't work on Android 4.0.3? Aim for a higher API?. That sucks when all you have to test is and Android 4.0.3 tablet.

Elias
Member #358
May 2000

The target SDK should always be the highest one available at the time - it does not mean older SDKs will not work. What is important in the min SDK: https://developer.android.com/guide/topics/manifest/uses-sdk-element

In fact, you cannot put any apps on the play store where target SDK is less than 26, so using a value less than 26 does not make too much sense. You can still set the min SDK to 15 and it will work fine on 4.0.3 devices.

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

Yeah, I meant aim for a higher minimum SDK.

Anyway, it was obvious the error was caused by the dlopen() call in android_system.c. I've read that there's been some changes in the way dlopen() works in Android, so I changed line 249 in android_system.c:

system_data.user_lib = dlopen(user_lib_name, RTLD_LAZY|RTLD_GLOBAL);

and hardcoded the full library path in the Android device like to this:

system_data.user_lib = dlopen("/data/data/org.liballeg.speed/lib/libnative-lib.so", RTLD_LAZY|RTLD_GLOBAL);

After doing this, the libnative-lib.so error was gone and it was instead replaced by an allegro_main-debug not found error. Adding the corresponding loadLibrary("allegro_main"); line in MainActivity.java solved the issue and now the Allegro demo is running both in the API 15 emulator and in the tablet. This is a cheap workaround as it requires to hardcode the path for dlopen() but I guess it's a good start.

[EDIT:] A slightly better version of the changes I made:

diff --git a/android/gradle_project/app/src/main/java/org/liballeg/app/MainActivity.java b/android/gradle_project/app/src/main/java/org/liballeg/app/MainActivity.java
index 262256473..0263e5aeb 100644
--- a/android/gradle_project/app/src/main/java/org/liballeg/app/MainActivity.java
+++ b/android/gradle_project/app/src/main/java/org/liballeg/app/MainActivity.java
@@ -37,6 +37,7 @@ public class MainActivity extends AllegroActivity {
         loadLibrary("allegro_memfile");
         loadLibrary("allegro_physfs");
         loadLibrary("allegro_video");
+        loadLibrary("allegro_main");
     }
     public MainActivity() {
         super("libnative-lib.so");
diff --git a/src/android/android_system.c b/src/android/android_system.c
index df5fefbf2..9cdd9896c 100644
--- a/src/android/android_system.c
+++ b/src/android/android_system.c
@@ -223,11 +223,13 @@ JNI_FUNC(bool, AllegroActivity, nativeOnCreate, (JNIEnv *env, jobject obj))
    system_data.apk_path = _jni_callStringMethod(env, system_data.activity_object, "getApkPath", "()Ljava/lang/String;");
    system_data.model = _jni_callStringMethod(env, system_data.activity_object, "getModel", "()Ljava/lang/String;");
    system_data.manufacturer = _jni_callStringMethod(env, system_data.activity_object, "getManufacturer", "()Ljava/lang/String;");
+   ALLEGRO_USTR *package_name = _jni_callStringMethod(env, system_data.activity_object, "getPackageName", "()Ljava/lang/String;");
    ALLEGRO_DEBUG("resources_dir: %s", al_cstr(system_data.resources_dir));
    ALLEGRO_DEBUG("data_dir: %s", al_cstr(system_data.data_dir));
    ALLEGRO_DEBUG("apk_path: %s", al_cstr(system_data.apk_path));
    ALLEGRO_DEBUG("model: %s", al_cstr(system_data.model));
    ALLEGRO_DEBUG("manufacturer: %s", al_cstr(system_data.manufacturer));
+   ALLEGRO_DEBUG("package_name: %s", al_cstr(package_name));
 
    ALLEGRO_DEBUG("creating ALLEGRO_SYSTEM_ANDROID struct");
    na_sys = system_data.system = (ALLEGRO_SYSTEM_ANDROID*)al_malloc(sizeof *na_sys);
@@ -245,8 +247,10 @@ JNI_FUNC(bool, AllegroActivity, nativeOnCreate, (JNIEnv *env, jobject obj))
    _al_unix_init_time();
 
    const char *user_lib_name = al_cstr(system_data.user_lib_name);
+   char *native_lib_path = NULL;
+   asprintf(&native_lib_path, "/data/data/%s/lib/libnative-lib.so", al_cstr(package_name));
    ALLEGRO_DEBUG("load user lib: %s", user_lib_name);
-   system_data.user_lib = dlopen(user_lib_name, RTLD_LAZY|RTLD_GLOBAL);
+   system_data.user_lib = dlopen(native_lib_path, RTLD_LAZY|RTLD_GLOBAL);
    if (!system_data.user_lib) {
       ALLEGRO_ERROR("failed to load user lib: %s", user_lib_name);
       ALLEGRO_ERROR("%s", dlerror());

With this I was able to run all the Allegro demos in both the tablet and the API 15 emulator as well as in the API 28 emulator. I'm not sure if this is a good solution in general, though.

Elias
Member #358
May 2000

Interesting. I'm not sure if the /data/data folder exists on newer devices, so might want to only do that if the device is on SDK 15.

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

Maybe do the original call to dlopen(), if it fails attempt the call with the full path and only if both fail return an error?.

Go to: