+44(0) 1234 567 890 info@domainname.com

November 08, 2013

cocos2d-x for Android, UnsatisfiedLinkError: Couldn't load cocos2dcpp

6:19 AM

Share it Please
Somedays ago, I encountered error when I built cocos2d-x 2.2 in my Android emulator device. I tried to run HelloCpp example from template which locate at $cocos2d-x-2.2_home/template/multi-platform-cpp/proj.android. Here, I used openSUSE 12.3 linux operating system. That errors are


       
11-07 12:09:31.758: E/AndroidRuntime(1800): FATAL EXCEPTION: main
11-07 12:09:31.758: E/AndroidRuntime(1800): java.lang.ExceptionInInitializerError
11-07 12:09:31.758: E/AndroidRuntime(1800):  at java.lang.Class.newInstanceImpl(Native Method)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at java.lang.Class.newInstance(Class.java:1319)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.os.Looper.loop(Looper.java:137)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at java.lang.reflect.Method.invokeNative(Native Method)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at java.lang.reflect.Method.invoke(Method.java:511)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at dalvik.system.NativeStart.main(Native Method)
11-07 12:09:31.758: E/AndroidRuntime(1800): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp: findLibrary returned null
11-07 12:09:31.758: E/AndroidRuntime(1800):  at java.lang.Runtime.loadLibrary(Runtime.java:365)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at java.lang.System.loadLibrary(System.java:535)
11-07 12:09:31.758: E/AndroidRuntime(1800):  at org.cocos2dx.hellocpp.HelloCpp.(HelloCpp.java:46)
11-07 12:09:31.758: E/AndroidRuntime(1800):  ... 15 more



It's make me so confused. Because there are no error in my eclipse project. After read many other tutorial of "cocos2d-x getting started on android" and forum in the internet, even make me so crazy. Many people got this error, but no solution. So, according to my experience to solve it, the following is my solution to run that HelloCpp cocos2d-x:

1. First, I set my NDK_ROOT. It will be used by build_native.sh script to compile cpp file, (not only in operating system which I used) but also used by AVD emulator console. How to do that?
- Open terminal and set bash_profile. (Remember that here I used openSUSE 12.3 linux OS)
vim /home/kirman/.bash_profile [enter]
- Set NDK_ROOT path
export NDK_ROOT=/home/kirman/android-ndk-r8d
- restart your computer

2. Second, set CPU/ABI of Android Virtual Devices (AVD) to ARM (armeabi-v7a). In here, I used API level 16 (Android 4.1.2).

3. Import file project to eclipse then run it. When successed all setting, an example in eclipse console will be looked like this (in case my emulator)
04:56:05 **** Incremental Build of configuration Default for project HelloCpp ****

bash /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/build_native.sh

NDK_ROOT = /home/kirman/android-ndk-r8d

COCOS2DX_ROOT = /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/../../..

APP_ROOT = /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/..

APP_ANDROID_ROOT = /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android

Using prebuilt externals

make: Entering directory `/home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android'

Install        : libcocos2dcpp.so => libs/armeabi/libcocos2dcpp.so

make: Leaving directory `/home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android'



04:56:06 Build Finished (took 621ms)

Here my screenshot when I successfull to run HelloCpp template project from cocos2d-x 2.2 :)


1 komentar:

Unknown said...

Thank you very much. This helps me to solve my issue.

I had to change to use ARM CPU.