dlopen failed: library "libmain.so" not found
SDL's SDLActivity looks for a library named libmain.so by default, but our CMake was building libswrenderersample.so.
Changed the library target name from ${CMAKE_PROJECT_NAME} to main:
# Before (Wrong)
add_library(${CMAKE_PROJECT_NAME} SHARED native-lib.cpp)
# Creates: libswrenderersample.so ❌
# After (Correct)
add_library(main SHARED native-lib.cpp)
# Creates: libmain.so ✅Removed manual library loading since SDLActivity does it automatically:
// Before (Unnecessary)
companion object {
init {
System.loadLibrary("swrenderersample")
}
}
// After (Automatic)
// SDLActivity loads libmain.so automatically ✅SDLActivity has this behavior:
- Looks for
libmain.soin the APK - Loads
libmain.soautomatically on startup - Calls
SDL_main()function from that library - Also loads
libSDL3.sowhichlibmain.sodepends on
Check the APK contains the right libraries:
unzip -l app/build/outputs/apk/debug/app-debug.apk | grep "\.so$"Should show:
lib/arm64-v8a/libSDL3.so
lib/arm64-v8a/libmain.so
lib/armeabi-v7a/libSDL3.so
lib/armeabi-v7a/libmain.so
...
If you want to keep a custom library name, you can override in SDLActivity:
class MainActivity : SDLActivity() {
override fun getLibraries(): Array<String> {
return arrayOf("SDL3", "yourcustomname")
}
}But the standard approach is to just use libmain.so. ✅
✅ Fixed - The app now builds libmain.so correctly
✅ Packaged - Both libSDL3.so and libmain.so are in the APK
✅ Loading - SDL will automatically load the library on startup
Ready to run! 🚀