Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [Android] Yet Another Allegro on Android Thread

This thread is locked; no one can reply to it. rss feed Print
[Android] Yet Another Allegro on Android Thread
kenmasters1976
Member #8,794
July 2007

I've just recently uploaded my Allegro based Android app to the Google Play Console for internal testing. When you upload an app, Google automatically tests it on a small number of devices. In this case, my Allegro app worked fine on 5 out of 6 devices; the one device where it fails to work is a Huawei P8 with ARM64 architecture.

The thing is, on this one device, my app fails at nativeOnCreate(), much like in this older thread I made. On that thread, I solved the problem on older devices by hardcoding the library path. Currently, in my project, I first attempt to load the native library libnative-lib.so with the default Allegro code and if that fails I try the hardcoded path as described above. This solution seems to work in most cases but for that particular device, Huawei P8, it won't. I've also tried using the Android nativeLibraryDir field but it didn't work either. Google provides a logcat file where the most relevant part would be the next:

10-24 21:58:48.127: I/allegro(19003): android  D 19003:     android_system.c:257  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] Attempting to load user lib: libnative-lib.so
10-24 21:58:48.127: I/allegro(19003): android  E 19003:     android_system.c:260  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] failed to load user lib: libnative-lib.so
10-24 21:58:48.127: I/allegro(19003): android  D 19003:     android_system.c:261  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] Attempting to load user lib: /data/app/com.example.AllegroTest-1/lib/arm64/libnative-lib.so
10-24 21:58:48.127: I/allegro(19003): android  E 19003:     android_system.c:265  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] failed to load user lib: /data/app/com.example.AllegroTest-1/lib/arm64/libnative-lib.so
10-24 21:58:48.127: I/allegro(19003): android  D 19003:     android_system.c:266  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] Attempting to load user lib: /data/data/com.example.AllegroTest/lib/libnative-lib.so
10-24 21:58:48.127: I/allegro(19003): android  E 19003:     android_system.c:270  Java_org_liballeg_android_AllegroActivity_nativeOnCreate [   0.00000] failed to load user lib: /data/data/com.example.AllegroTest/lib/libnative-lib.so

The logcat displays the three different options I currently use for attempting to load the native library; these options are using the default Allegro code, Android's nativeLibraryDir and the hardcoded path respectively.

What can possibly cause this issue on this particular device? One thing that stands out from the logcat is that, in the second form, it's attempting to load the library from /data/app/com.example.AllegroTest-1/lib/arm64/libnative-lib.so, note the arm64 which seems odd as the directory containing the native libraries for that architecture is actually named arm64-v8a.

Any other ideas for attempting to load/locate the native libraries? Note that other ARM64 devices don't have this issue.

Thanks.

[EDIT:] In an attempt to find the library location on Google's test device, I tried to use an ALLEGRO_FS_ENTRY inside nativeOnCreate() but attempting to do so crashes the application silently in the call to al_create_fs_entry(). I guess technically Allegro is not yet initialized at this point but since there's some more Allegro calls inside that function I thought that might work.

[EDIT 2:] After struggling for days without success with this issue I came up with a workaround that worked. Since I couldn't load the native lib no matter what path I used and given that, as described in the previous edit, exploring the files on the test device used by Google was not easy, I realized that I could try loading the native lib from the Java project, together with the rest of the Allegro libs, which were clearly being loaded without problems. As such, I added loadLibrary("native-lib"); to MainActivity.java. By doing so, the native lib is loaded without problems and when it is requested to dlopen() at android_system.c, the system will detect and use the library already loaded into memory. This seems to have to worked with the problematic device without causing any issues with other devices.

I thought this might be useful for others having this issue as well as for the Allegro devs.

amarillion
Member #940
January 2001
avatar

Do you think this change to MainActivity.java should be included in the library?

I can't judge whether this is a one-off workaround, or should really be considered a standard solution.

Also, congrats on uploading an app! Where can we find it?

kenmasters1976
Member #8,794
July 2007

This, indeed, feels more like a workaround than a solution, I'm not sure if this should be included in the Allegro source. Also, while it might work as an alternative in case the default code fails, I don't see an easy way to integrate both solutions into the source as one version loads the library from C and the other from Java; in this case, the Java code gets executed first, I guess, so it would require to always call loadLibrary() for the native lib in MainActivity.java independently of whether the C code would work or not.

Also, congrats on uploading an app! Where can we find it?

It's currently in the internal test track, not yet publicly available. The Google Play Console offers four different tracks to upload your app to: Internal test, Closed beta, Open beta and, finally, Production.

It's not a big deal of an app, it's rather simple, actually. I started working on this app as a challenge and at some point I thought "Man, I've seen worse things published on the Play Store so, why not?". I have plans to add more features (integration with Google Play Games would be interesting) but first I'd like to know if it's worth the effort, thus the decision to publish it.

Go to: