Android: SDL Error findLibrary returned null

I’m trying to get an SDL2 app working on Android using the NDK. When I try running my app I get an “SDL Error” dialog which contains the same information as the last line in the logcat output below.

05-25 20:50:10.692 32502-32502/org.libsdl.app W/ApplicationPackageManager: getCSCPackageItemText()
05-25 20:50:10.702 32502-32502/org.libsdl.app V/SDL: Device: ks01lte
05-25 20:50:10.702 32502-32502/org.libsdl.app V/SDL: Model: GT-I9506
05-25 20:50:10.702 32502-32502/org.libsdl.app V/SDL: onCreate(): null
05-25 20:50:10.702 32502-32502/org.libsdl.app D/dalvikvm: Trying to load lib /data/app-lib/org.libsdl.app-29/libSDL2.so 0x42a88788
05-25 20:50:10.702 32502-32502/org.libsdl.app D/dalvikvm: Added shared lib /data/app-lib/org.libsdl.app-29/libSDL2.so 0x42a88788
05-25 20:50:10.702 32502-32502/org.libsdl.app W/System.err: Couldn’t load main from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.libsdl.app-29.apk,libraryPath=/data/app-lib/org.libsdl.app-29]: findLibrary returned null

Can somebody please help me understand what is going on and how to fix this? My take on it is that libSDL2.so is the main ‘application’ which tries to libmain.so and its failing. Would that be correct?

I cannot see any other exceptions of stack dumps in my logcat. If I have a simple libmain.so which contains nothing but int main(){ return 0; } I get the same problem.

Any ideas please?

I don’t remember the details exactly, but you probably need to consider
this:

You need to supply your code in a library (e.g. libmain.so). The C/C++ file
where main(int, char**) is referenced needs to #include “SDL.h”, so that the
main function is replaced with something else.

And in the Java class you need to make sure that “libmain.so” is loaded
after “libSDL2.so”, just add it to the “getLibraries()” function, if not
already done.

This should work.

---------- P?vodn? zpr?va ----------
Od: SparkyNZ
Komu: sdl at lists.libsdl.org
Datum: 25. 5. 2016 11:07:54
P?edm?t: [SDL] Android: SDL Error findLibrary returned null

"

I’m trying to get an SDL2 app working on Android using the NDK. When I try
running my app I get an “SDL Error” dialog which contains the same
information as the last line in the logcat output below.

05-25 20:50:10.692 32502-32502/org.libsdl.app W/ApplicationPackageManager:
getCSCPackageItemText()
05-25 20:50:10.702 32502-32502/org.libsdl.app V/SDL: Device: ks01lte
05-25 20:50:10.702 32502-32502/org.libsdl.app V/SDL: Model: GT-I9506
05-25 20:50:10.702 32502-32502/org.libsdl.app V/SDL: onCreate(): null
05-25 20:50:10.702 32502-32502/org.libsdl.app D/dalvikvm: Trying to load lib
/data/app-lib/org.libsdl.app-29/libSDL2.so 0x42a88788
05-25 20:50:10.702 32502-32502/org.libsdl.app D/dalvikvm: Added shared lib /
data/app-lib/org.libsdl.app-29/libSDL2.so 0x42a88788
05-25 20:50:10.702 32502-32502/org.libsdl.app W/System.err: Couldn’t load
main from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.libsdl.
app-29.apk,libraryPath=/data/app-lib/org.libsdl.app-29]: findLibrary
returned null

Can somebody please help me understand what is going on and how to fix this?
My take on it is that libSDL2.so is the main ‘application’ which tries to
libmain.so and its failing. Would that be correct?

I cannot see any other exceptions of stack dumps in my logcat. If I have a
simple libmain.so which contains nothing but int main(){ return 0; } I get
the same problem.

Any ideas please?_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

hardcoredaniel wrote:

And in the Java class you need to make sure that “libmain.so” is loaded after “libSDL2.so”, just add it to the “getLibraries()” function, if not already done.

Java class… Hmmm. My NDK app doesn’t have a java class as far as I know because its pure NDK. I guess I will have to look at the SDL2 source itself and find out what generates the “SDL Error” dialog.

I can build and run the SDL example that comes with the SDL2 source. In fact, I took a copy of that and began adding my own additional source files and static libraries so I’m not sure why it has stopped working. That’s why I need to understand more about what goes on.

I was referring to this file:

http://hg.libsdl.org/SDL/file/7cbfd97f1430/android-project/src/org/libsdl/
app/SDLActivity.java

which is part of your project. But if you haven’t changed it, then it
automatically tries to load the “main” library after the “SDL2” library.
(This means also that the “main” library is mandatory.)

Regards,

Daniel

---------- P?vodn? zpr?va ----------
Od: SparkyNZ
Komu: sdl at lists.libsdl.org
Datum: 25. 5. 2016 22:45:04
P?edm?t: Re: [SDL] Android: SDL Error findLibrary returned null

"

                      hardcoredaniel wrote:	 

And in the Java class you need to make sure that “libmain.so” is loaded
after “libSDL2.so”, just add it to the “getLibraries()” function, if not
already done.

Java class… Hmmm. My NDK app doesn’t have a java class as far as I know
because its pure NDK. I guess I will have to look at the SDL2 source itself
and find out what generates the “SDL Error” dialog.

I can build and run the SDL example that comes with the SDL2 source. In
fact, I took a copy of that and began adding my own additional source files
and static libraries so I’m not sure why it has stopped working. That’s why
I need to understand more about what goes on._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

[quote="hardcoredaniel"http://hg.libsdl.org/SDL/file/7cbfd97f1430/android-project/src/org/libsdl/app/SDLActivity.java

which is part of your project. But if you haven’t changed it, then it automatically tries to load the “main” library after the “SDL2” library. (This means also that the “main” library is mandatory.)[/quote]

I haven’t touched that. From what I can see, my .apk file isn’t changing at all when I run ndk-build. That would mean that the same broken application is being installed on my phone over and over again even though I’m recompiling my source…

Code:
SparkbookPro:android-TT admin$ find . -name “*.apk”
./app/build/outputs/apk/app-debug-unaligned.apk
./app/build/outputs/apk/app-debug.apk

The timestamps for the above .apk files never change when I do an ndk-build

I don’t know what I’ve done. Any idea how to get ndk-build to rebuild my .apk files?

I’ve been building my code from the command prompt and then using Android Studio to do a ‘Clean and Run’ to install my app. I obviously have some discontinuity between Android Studio and the command line.

hardcoredaniel wrote:

You need to supply your code in a library (e.g. libmain.so). The C/C++ file where main(int, char**) is referenced needs to #include “SDL.h”, so that the main function is replaced with something else.

And in the Java class you need to make sure that “libmain.so” is loaded after “libSDL2.so”, just add it to the “getLibraries()” function, if not already done.

OK, I can see the code in the java class that loads library “SDL” and “main”. I wonder… is there a standard that the library needs to adhere to before it will load correctly? I’m wondering if I’m missing a method or function that may be required for a library to load successfully. I’m sure that there are standard DLL entry/init functions with the likes of Windows but I have no idea when it comes to Android Java trying to load JNI libraries.

I’ve tried building my app likes this with an almost empty main.cpp:

LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c
main.cpp

If my main.cpp only contains an empty main() function, would this cause my libmain to fail to load because a method/function is missing perhaps??

ndk-build does not build your app. It will always build the native part
only. You need to rebuild the app itself afterwards.

I have no clue why Android Studio doesn’t pick up your changes to rebuild
the apk. So far I always used the command line to do this.

I use “android update project --path .” (from my memory, don’t remember the
exact command line) to generate the necessary project files once, and then
"and clean debug" to build the app. Finally “ant installd” will upload it to
your device/emulator.

Android Studio uses gradle to do all of this, but don’t ask me about details
:wink:

---------- P?vodn? zpr?va ----------
Od: SparkyNZ
Komu: sdl at lists.libsdl.org
Datum: 27. 5. 2016 3:13:47
P?edm?t: Re: [SDL] Android: SDL Error findLibrary returned null

"

[quote="hardcoredaniel"http://hg.libsdl.org/SDL/file/7cbfd97f1430/android-
project/src/org/libsdl/app/SDLActivity.java

which is part of your project. But if you haven’t changed it, then it
automatically tries to load the “main” library after the “SDL2” library.
(This means also that the “main” library is mandatory.)[/quote]

I haven’t touched that. From what I can see, my .apk file isn’t changing at
all when I run ndk-build. That would mean that the same broken application
is being installed on my phone over and over again even though I’m
recompiling my source…

                              Code:	 

SparkbookPro:android-TT admin$ find . -name “*.apk”
./app/build/outputs/apk/app-debug-unaligned.apk
./app/build/outputs/apk/app-debug.apk

The timestamps for the above .apk files never change when I do an ndk-build

I don’t know what I’ve done. Any idea how to get ndk-build to rebuild my .
apk files?

I’ve been building my code from the command prompt and then using Android
Studio to do a ‘Clean and Run’ to install my app. I obviously have some
discontinuity between Android Studio and the command line._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

There are no mandatory functions that you must implement. You can implement
sth. like a “JNI_OnLoad” if you really want to. Although there is also a
"JNI_OnUnload" (IIRC) it is pretty hard to get that one ever called. I have
not used either yet.

Your “loadLibrary” should never fail, no matter what content your library
has (unless of course you are depending on another library that has not been
loaded yet so that you have unresolved symbols - that’s no different than
other OS’s). You would get failures later if you are instructing the VM to
call a specific “native” (e.g. C/C++) function that cannot be found.

With respect to SDL you should not have to worry a lot about this, because
all the Java --> C and back stuff is handled by SDL already, and all you
need to do is to supply a “libmain.so” with a main() function that contains
your code, and is loaded after SDL itself is loaded.

---------- P?vodn? zpr?va ----------
Od: SparkyNZ
Komu: sdl at lists.libsdl.org
Datum: 27. 5. 2016 3:50:03
P?edm?t: Re: [SDL] Android: SDL Error findLibrary returned null

"

                      hardcoredaniel wrote:	 

You need to supply your code in a library (e.g. libmain.so). The C/C++ file
where main(int, char**) is referenced needs to #include “SDL.h”, so that the
main function is replaced with something else.

And in the Java class you need to make sure that “libmain.so” is loaded
after “libSDL2.so”, just add it to the “getLibraries()” function, if not
already done.

OK, I can see the code in the java class that loads library “SDL” and
"main". I wonder… is there a standard that the library needs to adhere to
before it will load correctly? I’m wondering if I’m missing a method or
function that may be required for a library to load successfully. I’m sure
that there are standard DLL entry/init functions with the likes of Windows
but I have no idea when it comes to Android Java trying to load JNI
libraries.

I’ve tried building my app likes this with an almost empty main.cpp:

LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c
main.cpp

If my main.cpp only contains an empty main() function, would this cause my
libmain to fail to load because a method/function is missing perhaps??_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

Maybe it worth trying to unzip you .APK and see what’s inside.
Your folder should contains ./libs//libSDL2.so and
./lib//libmain.soOn 27 May 2016 at 09:26, hardcoredaniel wrote:

There are no mandatory functions that you must implement. You can
implement sth. like a “JNI_OnLoad” if you really want to. Although there is
also a “JNI_OnUnload” (IIRC) it is pretty hard to get that one ever called.
I have not used either yet.

Your “loadLibrary” should never fail, no matter what content your library
has (unless of course you are depending on another library that has not
been loaded yet so that you have unresolved symbols - that’s no different
than other OS’s). You would get failures later if you are instructing the
VM to call a specific “native” (e.g. C/C++) function that cannot be found.

With respect to SDL you should not have to worry a lot about this, because
all the Java --> C and back stuff is handled by SDL already, and all you
need to do is to supply a “libmain.so” with a main() function that contains
your code, and is loaded after SDL itself is loaded.

---------- P?vodn? zpr?va ----------
Od: SparkyNZ
Komu: sdl at lists.libsdl.org
Datum: 27. 5. 2016 3:50:03
P?edm?t: Re: [SDL] Android: SDL Error findLibrary returned null

hardcoredaniel wrote:
You need to supply your code in a library (e.g. libmain.so). The C/C++
file where main(int, char**) is referenced needs to #include “SDL.h”, so
that the main function is replaced with something else.

And in the Java class you need to make sure that “libmain.so” is loaded
after “libSDL2.so”, just add it to the “getLibraries()” function, if not
already done.

OK, I can see the code in the java class that loads library “SDL” and
"main". I wonder… is there a standard that the library needs to adhere to
before it will load correctly? I’m wondering if I’m missing a method or
function that may be required for a library to load successfully. I’m sure
that there are standard DLL entry/init functions with the likes of Windows
but I have no idea when it comes to Android Java trying to load JNI
libraries.

I’ve tried building my app likes this with an almost empty main.cpp:

LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c
main.cpp

If my main.cpp only contains an empty main() function, would this cause my
libmain to fail to load because a method/function is missing perhaps??


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

slvn wrote:

Maybe it worth trying to unzip you .APK and see what’s inside.

Your folder should contains ./libs//libSDL2.so and ./lib//libmain.so

Thanks. I have had a look and it does contain those 2 .so files. I suspect hardcoredaniel may be right - it could be related to missing shared libraries. Been a bit pushed for time lately so I haven’t had much of a chance to work through this. I will respond with my findings though in case it helps somebody else in the future. Its just a shame that Android Studio doesn’t properly support NDK development still. Its been ages… The whole toolchain is so frustrating. I’ve had problems getting it all set up on my Windows laptop so I’m currently struggling with my Mac in the meantime…

  • Maybe you haven’t included the file “SDL_android_main.c” in your project
    / libmain.so ?

For sure, you only need libmain.so and libSDL2.so, of the correct
architecture!
(but you still can put libSDL2_image.so, or you own shared libraries).

Also, there are some issue of function missing function (eg “srand()” when
loading the share libraries, with some ndk, and some targeted api.
A quick workaround for that is to remove the compilation of "src/test/*.c"
from SDL/Android.mk.

Android Studio is not absolutely needed,
you have, at least two other ways to compile :

  • use NDK + ant. (ndk-build, then ant release), but this is going to be
    deprecated in the future I guess …
  • use NDK + gradle + ndk plugin, then (./gradlew AssembleRelease). This is
    more difficult to setup because you need to create a build.gradle …On 30 May 2016 at 04:23, SparkyNZ wrote:

slvn wrote:

Maybe it worth trying to unzip you .APK and see what’s inside.

Your folder should contains ./libs//libSDL2.so and ./lib//libmain.so

Thanks. I have had a look and it does contain those 2 .so files. I suspect
hardcoredaniel may be right - it could be related to missing shared
libraries. Been a bit pushed for time lately so I haven’t had much of a
chance to work through this. I will respond with my findings though in case
it helps somebody else in the future. Its just a shame that Android Studio
doesn’t properly support NDK development still. Its been ages… The whole
toolchain is so frustrating. I’ve had problems getting it all set up on my
Windows laptop so I’m currently struggling with my Mac in the meantime…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

slvn wrote:

you have, at least two other ways to compile :

  • use NDK + ant. (ndk-build, then ant release), but this is going to be deprecated in the future I guess …

Yeah I have been trying to use ANT these past few days and I’m struggling with that. Even with verbose output enabled, I don’t find a lot of the Android related tools very helpful. I’m currently hoping somebody will help me on Stackoverflow with my latest dilemma below:

I went back basics though - I built the libSDL2.so file myself for the armeabi-v7a architecture and I’m building my own libmain.so (which just contains a tiny main.cpp SDL test and the SDL_android_main.c). After building, I end up with libSDL2.so and libmain.so in my jniLibs folder.

I keep getting a ‘Found duplicate file for APK: AndroidManifest.xml’ error and I have absolutely no idea why:

Code:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating app-debug-unaligned.apk and signing it with a debug key…
[apkbuilder] Found duplicate file for APK: AndroidManifest.xml
[apkbuilder] Origin 1: /Work/TT/android-TT/app/src/main/bin/app.ap_
[apkbuilder] Origin 2: /Work/TT/android-TT/app/src/main/AndroidManifest.xml

I’m running ‘ant -v debug’ from the /Work/TT/android-TT/app/src/main folder (I set ant.properties so I don’t need a ‘src’ folder under main). My complete output is in the Stackoverflow posting.

The challenge now is to get an APK to build with ANT - I am giving up with Android Studio for now - if I can get the build system to work manually myself.

My quick look :

  • I’ve never seen this “duplicate” error before. I would stick with the
    usual source tree …
  • NDK_TOOLCHAIN_VERSION=4.4.3, not sure which toolchain this selects.
    with ndk-r11c, you can select either clang or gcc 4.9. values would be
    clang or 4.9. not 4.4.3 …
  • I wouldn’t use those flags right now, keep them for later :slight_smile:
    "-mfloat-abi=softfp
    -mfpu=neon
  • the libmain.so should be in “libs//”, eg
    "./libs/armeabi-v7a/".(even if it should normally work in ./libs/)
  • … is your device actually supporting armeabi-v7a ? not only armeabi ?
    (that would a very old one …)

Maybe you have this error “findlibary returns null” only because the source
tree is not compliant.

Cheers,On 31 May 2016 at 21:40, SparkyNZ wrote:

slvn wrote:

you have, at least two other ways to compile :

  • use NDK + ant. (ndk-build, then ant release), but this is going to be
    deprecated in the future I guess …

Yeah I have been trying to use ANT these past few days and I’m struggling
with that. Even with verbose output enabled, I don’t find a lot of the
Android related tools very helpful. I’m currently hoping somebody will help
me on Stackoverflow with my latest dilemma below:

http://stackoverflow.com/questions/37541808/ant-found-duplicate-file-for-apk-androidmanifest-xml

I went back basics though - I built the libSDL2.so file myself for the
armeabi-v7a architecture and I’m building my own libmain.so (which just
contains a tiny main.cpp SDL test and the SDL_android_main.c). After
building, I end up with libSDL2.so and libmain.so in my jniLibs folder.

I keep getting a ‘Found duplicate file for APK: AndroidManifest.xml’ error
and I have absolutely no idea why:

Code:

[apkbuilder] Current build type is different than previous build: forced
apkbuilder run.
[apkbuilder] Creating app-debug-unaligned.apk and signing it with a debug
key…
[apkbuilder] Found duplicate file for APK: AndroidManifest.xml
[apkbuilder] Origin 1: /Work/TT/android-TT/app/src/main/bin/app.ap_
[apkbuilder] Origin 2: /Work/TT/android-TT/app/src/main/AndroidManifest.xml

I’m running ‘ant -v debug’ from the /Work/TT/android-TT/app/src/main
folder (I set ant.properties so I don’t need a ‘src’ folder under main). My
complete output is in the Stackoverflow posting.

The challenge now is to get an APK to build with ANT - I am giving up with
Android Studio for now - if I can get the build system to work manually
myself.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker

slvn wrote:

My quick look :

  • I’ve never seen this “duplicate” error before. I would stick with the usual source tree …
  • NDK_TOOLCHAIN_VERSION=4.4.3, not sure which toolchain this selects.
    ?? with ndk-r11c, you can select either clang or gcc 4.9. values would be clang or 4.9. not 4.4.3 …
  • I wouldn’t use those flags right now, keep them for later :slight_smile: "-mfloat-abi=softfp -mfpu=neon- the libmain.so should be in “libs//”, eg “./libs/armeabi-v7a/”.(even if it should normally work in ./libs/)
  • … is your device actually supporting armeabi-v7a ? not only armeabi ? (that would a very old one …)
    Maybe you have this error “findlibary returns null” only because the source tree is not compliant.

Yeah I will try and start over again afresh. I would like a standalone NDK SDL project that I can build from the command line (using ANT etc) and expand upon without it breaking. That was kind-of how I started. I had a simple SDL Android Studio project which I added my cross-platform source to and then it all fell apart. My quest at the moment is really to understand how the environment must be configured (ie. what constraints I have to fit within). ANT and ndk-build seem very pedantic about tree layout as you say.

I believe my device is armeabi-v7a (I’m using??a Samsung S4 or Samsung N5100 tablet). I got rid of the other architectures temporarily to speed up my compile time while working through compiling my cross-platform source. Great that it compiles… shame I can’t see it actually running on my tablet… :frowning:

Luckily today I have most of the day off work to try and get to the bottom of all this.

OK… I tried starting this from the beginning. Here’s what I’ve done:

Well this is a dramatic improvement!

  1. I copied the SDL android-project into my /work folder
  2. I replace jni/Android.mk with my own that includes libSDL2.so
  3. I copied my main.cpp into the jni/src folder
  4. Changed AndroidManifest.xml minSdkVersion and targetSdkVersion to 14
  5. Added APP_PLATFORM := android-14 to Application.mk
  6. Removed armeabi and x86 from Application.mk
  7. Copied assets/image.BMP into same (root) folder as jni folder
  8. ndk-build (from within jni folder -> successful)
  9. cd … (to folder with AndroidManifest.xml)
  10. android update project --name app --path . --target “android-14”
  11. ant -v debug (Wow! Successful)
  12. adb install -r bin/app-debug.apk
  13. adb shell am start -n org.libsdl.app/org.libsdl.app.SDLActivity

No errors, and it runs!

Hmm. I’m now wondering if Android Studio upset something in the SDL2 standard template project tree

Now I’ll have to remove the super-imposed Android Studio rubbish that’s in my cross-platform project and implement the project tree structure in my clean example.

What a journey!

I should also have added that my app is now running. Its crashing, but for other reasons. Nice to see it logging some debug from the main() function!

Ayuda porfavor yo tengo un error, me meto a un juego me manda este error se llama “sdl error" Y es lo que dice

“an error occurred while trying to start the application . Please try agrain and / or restart

Error:dlopen failded cannot locate symbol “atof" referenced by “libpng16.so"
Lo que dice en español “Ocurrió un error al intentar iniciar la aplicación. Intente agrain y / o reinicie

Error: dlopen falló no puede localizar el símbolo “atof” al que hace referencia “libpng16.so”"

Nomas me da la opcion de picarle a exit no se que hacer no se si tenga que ver que mi version de CELULAR es 4.42 pero no se ayuda no se que pueda ser