GdxRuntimeException on Android: couldn't load shared library 'gdx' for target

omarsafwany picture omarsafwany · May 22, 2013 · Viewed 7.5k times · Source

I've developed a Libgdx application and tested it on my Samsung Galaxy S3(4.1.2) where it is working great. I tried to test it on a Galaxy Grand(4.1.2) but it failed. In the logcat, I found the following:

caused by com.badlogic.gdx.utils.GdxRuntimeException couldn't load shared library 'gdx' for target: Linux, 32-bit

This happened when changing the device only so any idea what is the cause?!

The complete logcat:

05-22 20:25:01.745: E/AndroidRuntime(12725): FATAL EXCEPTION: main
05-22 20:25:01.745: E/AndroidRuntime(12725): java.lang.ExceptionInInitializerError
05-22 20:25:01.745: E/AndroidRuntime(12725):    at java.lang.Class.newInstanceImpl(Native Method)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at java.lang.Class.newInstance(Class.java:1319)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.os.Looper.loop(Looper.java:137)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at android.app.ActivityThread.main(ActivityThread.java:4935)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at java.lang.reflect.Method.invokeNative(Native Method)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at java.lang.reflect.Method.invoke(Method.java:511)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at dalvik.system.NativeStart.main(Native Method)
05-22 20:25:01.745: E/AndroidRuntime(12725): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx' for target: Linux, 32-bit
05-22 20:25:01.745: E/AndroidRuntime(12725):    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:104)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:34)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:61)
05-22 20:25:01.745: E/AndroidRuntime(12725):    ... 15 more
05-22 20:25:01.745: E/AndroidRuntime(12725): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gdx: findLibrary returned null
05-22 20:25:01.745: E/AndroidRuntime(12725):    at java.lang.Runtime.loadLibrary(Runtime.java:365)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at java.lang.System.loadLibrary(System.java:535)
05-22 20:25:01.745: E/AndroidRuntime(12725):    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:100)
05-22 20:25:01.745: E/AndroidRuntime(12725):    ... 17 more

Answer

Farskeptic picture Farskeptic · Aug 15, 2013

I received the exact same error as the original post when I tried to load projects generated by libGDX into Android Studio:

> "caused by com.badlogic.gdx.utils.GdxRuntimeException couldn't load
> shared library 'gdx' for target: Linux, 32-bit"

After a bit of research (specifically www.badlogicgames.com/forum/viewtopic.php?f=11&t=9097), I found this excellent tutorial by evilEntity that showed how to import libGDX projects into Android Studio:

http://imgur.com/a/IBFIV.

I can't repeat the tutorial verbatim as it's both text and screenshots, but following the steps allowed me to import the generated projects with only the modifications listed in the tutorial:

Please note that I am repeating evilentity's answer here because it's in a different forum on a different site, and there's ample comments in Stack overflow indicating that it's bad form to simply post links to solutions on other sites.

Please also note that I am including this answer here as it was the error message contained in omarsafwany's question that was the key point for me, rather than the specific circumstances around his issue. Hopefully that's OK.

  1. Import project:
    • Select top folder containing all three generated projects (shared, desktop, android)
    • Select "Create proejct from existing sources"
    • Rename the three libraries (libs = LibGDX-Desktop, libs1 = LibDGX-Android, libs2 = LibDGX-Shared)
    • Accept remaining defaults and click "finish"
    • All three projects should appear in your project explorer.
  2. Export shared library
    • Right-click shared module and select "Open Module Settings"
    • Go to shared module and select "export" next to libgdx shared library
    • Go to android module and add shared module as dependency (by clicking on green +)
    • Go to desktop module and add shared module as dependency (by clicking on green +)
  3. Edit Android Run Configuration
    • rename android configuration by adding "-android" to end of existing name
    • select "Show chooser dialog" in "target device"
  4. Add Desktop Run Configuration
    • Click on green + and select "application"
    • Give it some name at the top, next click on ... next to 'Main class' field. In the dialog select project and find main class of desktop starter. Click ok.
    • Now we need to change working directory. Click on ... and from folder view select assets folder of android starter. Without it desktop starter wont be able to find required images and other things to run.
    • Last things to do is to select classpath. Select desktop module. Click ok.

Details:

  • Android Studio Version: AI-130.737825 (July 11, 2013)
  • JRE: 1.7.0_25
  • libGDX: Nightly build from 8/15/2013
  • Android Device: Google Nexus 7
  • Projects generated by: gdx-setup-ui.jar (downloaded from http://libgdx.badlogicgames.com/nightlies/)