Building Android applications "libSDL3.so not found"

Is anyone else out there having a terrible time building for android? Other platforms built so much more easily. I’m working on a Mac, though I’m more of a Linux-person.

I’ve gone through the README-android.md a few times with a few fresh downloads to keep things clean. I started with SDL2.28.1, but couldn’t get anything to work, and am now trying with SDL3 (last re-downloaded from Github yesterday). I’m getting further (I think?) with SDL3, and I’d prefer to keep working with it.

Running the androidbuild.sh program on either my own minimal program (draw rectangle and exit on any key press) or with ‘test’ programs all failed with linking errors. I opened a bug report on that since it seems more like an issue with the androidbuild.sh script (#8078), especially after trying several permutations of versions for JDK, SDK, Android Studio and so on. I feel like I’ve exhausted my options with that script on both SDL2 and SDL3. I’ve tried the command line, Android Studio, and Visual Studio for Mac approaches. The command line and Android Studio always give me identical errors, and Visual Studio doesn’t seem to support the Mac, C/C++, and Android mix.

I’ve been iterating through the approach to copy the android-project directory and add my source file and the SDL library into it. It will actually build and deploy to an emulator. The problem is that when I launch the app, I get

SDL Error
An error occurred while trying to start the application. Please try again and/or reinstall

Error: dlopen failed: library 'libSDL3.so' not found

When I search the ‘app’ directory for libSDL3.so, I see it in many places:

./app/build/intermediates/cxx/Debug/3q3j6750/obj/local/arm64-v8a/libSDL3.so
./app/build/intermediates/merged_native_libs/debug/out/lib/arm64-v8a/libSDL3.so
./app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libSDL3.so
./app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libSDL3.so
./app/jni/SDL/build/android/obj/local/arm64-v8a/libSDL3.so
./app/jni/SDL/build/android/lib/arm64-v8a/libSDL3.so

I’m guessing they are all arm64-v8a because some Gradle check has identified I’ve most recently been building for a Pixel 7 Pro, which has an ARM processor and is skipping the other builds for now.

I’ve played with copying libSDL3.so into different, funny places to see if I could get a new error. Alas, nothing seemed to be recognized. I made some tweaks to the /app/jni/src/Android.mk file to try to help it find one of the libSDL3.so files it was generating. Nothing worked, so eventually I reverted all of my changes. I find it weird that the default is to compile with a .so instead of compiling statically, since I don’t imagine that the .so would be shared across more than one application. I also tried updating 'app/jni/src/Android.mk “LOCAL_SHARED_LIBRARIES := SDL3” to “LOCAL_SHARED_LIBRARIES := SDL3_static”. That resulted in “undefined reference” errors to all of the SDL functions in any test programs. I have done a lot with pretty elaborate makefiles, but I’m not familiar with Gradle and have reverted everything in all Android.mk files to their originals, with the exception of the one line where the comment says to include my application’s source file (main.cpp).

I’m checking to see if anyone else has also found this process comparatively painful. I feel disconcertingly special since no one else seems to have reported a 'libSDL3.so not found" error here before. I’d also appreciate any tips from people out there who’ve managed to get a successful build.

I’m currently building on Android using SDL 2.26.2 (Android Studio in Windows) and that is working. I’ve not yet tried 2.28.1 but I wouldn’t have expected any major differences. I can’t use SDL3.

I’m running into this issue now with a project that I generated from the “androidbuild.sh” script, and modified to support the “Dear ImGui” libraries.

I’m using openjdk-19 on Ubuntu 22.04 with Android Studio (see screenshot).

I ran “adb logcat -d > android_log.txt” and found this reference to package which may be helpful:

01-26 07:08:40.701  5278  5278 E AndroidRuntime: FATAL EXCEPTION: SDLActivity
01-26 07:08:40.701  5278  5278 E AndroidRuntime: Process: com.example.imgui, PID: 5278
01-26 07:08:40.701  5278  5278 E AndroidRuntime: java.lang.UnsatisfiedLinkError: No implementation found for boolean org.libsdl.app.SDLActivity.nativeAllowRecreateActivity() (tried Java_org_libsdl_app_SDLActivity_nativeAllowRecreateActivity and Java_org_libsdl_app_SDLActivity_nativeAllowRecreateActivity__) - is the library loaded, e.g. System.loadLibrary?
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at org.libsdl.app.SDLActivity.nativeAllowRecreateActivity(Native Method)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at org.libsdl.app.SDLActivity.onCreate(SDLActivity.java:343)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:8595)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:8573)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:205)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:294)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8177)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
01-26 07:08:40.701  5278  5278 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)