Running on Android Studio

I’m following http://cocos2d-x.org/docs/installation/Android-Studio/index.html. However when I try to run cpp-tests it comes up with Unfortunately, libcocos2dx has stopped

In logcat, it shows:

09-13 17:33:09.090 2872-2872/org.cocos2dx.cpp_tests E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.UnsatisfiedLinkError: Couldn't load cpp_tests: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:365)
        at java.lang.System.loadLibrary(System.java:535)
        at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
        at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

I’m using cocos2d-x v3.10, ndk r10e, and android-16 and testing on a virtual emulator.

How do I get this to run properly?

I’m not sure yet. When I wrote that documentation, I tested on hardware with r10c and Android 2.1 while it was still in a beta phase.

The beta phase of what? Android Studio?

Sorry for the late reply, I was busy.

I know the problem is within Android Studio’s emulator as I just tried cpp-tests using MEmu emulator and it worked.

It might be that you are using a x86 emulator but cocos compile is doing only Arm NDK build by default. Either try using Arm emulator or update the .mk files to do x86 NDK builds also.

I tried using an ARM emulator but it still didn’t work.

This is my updated logcat (I missed the beginning when I first posted.):

$ adb shell am start -n "org.cocos2dx.cpp_tests/org.cocos2dx.cpp_tests.AppActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 1490 on device Nexus_7_2012_API_16 [emulator-5554]
D/dalvikvm: Not late-enabling CheckJNI (already on)
E/Trace: error opening trace file: No such file or directory (2)
I/dalvikvm: Could not find method android.app.Application.registerOnProvideAssistDataListener, referenced from method com.android.tools.fd.runtime.BootstrapApplication.registerOnProvideAssistDataListener
W/dalvikvm: VFY: unable to resolve virtual method 206: Landroid/app/Application;.registerOnProvideAssistDataListener (Landroid/app/Application$OnProvideAssistDataListener;)V
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.app.Application.unregisterOnProvideAssistDataListener, referenced from method com.android.tools.fd.runtime.BootstrapApplication.unregisterOnProvideAssistDataListener
W/dalvikvm: VFY: unable to resolve virtual method 209: Landroid/app/Application;.unregisterOnProvideAssistDataListener (Landroid/app/Application$OnProvideAssistDataListener;)V
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/InstantRun: Instant Run Runtime started. Android package is org.cocos2dx.cpp_tests, real application class is null.
W/InstantRun: No instant run dex files added to classpath
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
W/dalvikvm: VFY: unable to resolve check-cast 126 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x025e
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
W/dalvikvm: VFY: unable to resolve const-class 126 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
D/dalvikvm: VFY: replacing opcode 0x1c at 0x0060
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xae5552a0)
E/AndroidRuntime: FATAL EXCEPTION: main
              java.lang.UnsatisfiedLinkError: Couldn't load cpp_tests: findLibrary returned null
                  at java.lang.Runtime.loadLibrary(Runtime.java:365)
                  at java.lang.System.loadLibrary(System.java:535)
                  at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
                  at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
                  at android.app.Activity.performCreate(Activity.java:5008)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                  at android.app.ActivityThread.access$600(ActivityThread.java:130)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:137)
                  at android.app.ActivityThread.main(ActivityThread.java:4745)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:511)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                  at dalvik.system.NativeStart.main(Native Method)
I/Process: Sending signal. PID: 1490 SIG: 9

       [ 01-01 00:04:45.300   889:  935 D/         ]
       HostConnection::get() New Host Connection established 0xb89460f0, tid 935
Application terminated.

Here is the same thing. When i try to run , i get this. No matter what i use for run. Real device, virtual device. It doesn’t matter. Just getting Fatal exception something like this.

09-30 18:30:09.811 2778-2778/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ogrenme.teatone.deneme, PID: 2778
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/ogrenme.teatone.deneme-1/base.apk”],nativeLibraryDirectories=[/data/app/ogrenme.teatone.deneme-1/lib/x86, /vendor/lib, /system/lib]]] couldn’t find “libMyGame.so”
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:264)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

@teatone This happens because you don’t compile for the architecture you are trying to test on.

Change to APP_ABI := armeabi armeabi-v7a x86 in Application.mk file and recompile.

nothing is changed

1 Like

@teatone @xxYxx it seems you forgot to compile your code first. Compiling C++ code is currently not supported in Android Studio, you have to use cocos console instead:

cocos compile -p android --android-studio

After executing this command you should be able to run your project from within Android Studio

I did it before posting about my issue. Even I make new project for just compile it properly then try to open with random devices.

I got same problem.