Android Studio & Cocos2Dx

I need to get a Cocos2D-X project running in Android Studio.
Before, I was using this tutorial with cocos2d-x version 3.4 to get the project up and running. But since then I tried to upgrade to version 3.7 to get the integrated Android Studio project but the cocos compile command threw up errors (Error 2) which I couldn’t figure out.

Using the compile command specifically for Android Studio cocos compile -p android --android-studio also fails with:

  • What went wrong:
    Execution failed for task ‘:findingGameX:processDebugResources’.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Users/ConorM/Library/Android/sdk/build-tools/22.0.1/aapt’’ finished with non-zero exit value 1

I switched back to version 3.4 and now that will build with the cocos compile but won’t build in Android Studio. Throwing Error (12, 0) about how the NDK is deprecated and to either use the experimental Gradle or allow deprecated NDK in the gradle.settings file.

I’ve tried both and neither seem to help.

Has anyone gotten around any of these problems?

I think v3.8.1 supports Android Studio at this point.

Use the latest Cocos2d-x version, you can see our video for help setting up a project in Cocos2d-x https://www.youtube.com/watch?v=gdOkbXYsf04

Tried that there on a fresh user account and I’m still getting build errors on the cocos compile.

Gonna abandon the Cocos approach for now. Thanks for the replies!

Version 3.8.1 should work with Android Studio.

It works for me.

Hi, when you say v3.8.1 works with Android Studio, do you mean I can do NDK debugging?

I reinstalled my Android SDK’s and that fixed all the build issues.

Some more comprehensive tutorials on this topic would be really appreciated by the community, I think. Using Eclipse+ADT for Android debugging and emulation is as it is quite hard and bug-filled, but as I write this comment it becomes more and more impossible because it is basically not maintained anymore. Android Studio is the legitimate replacement for it with VS2015 as an additional hopeful. Even if SonarSystems’ efforts is being appreciated, a 7min video can’t really cover but the bare essentials.

2 Likes

@Scratch
Can You tell me exactly what You did with the SDK’s? I have the same issue and don’t know what to do :frowning:

@Lem
I completely uninstalled then reinstalled Android Studio and all the SDKs and stuff that came with it.

Im using Android Studio now and Im getting this error using the Cocos Helper classes. Ive been at this for hours :frowning:

FATAL EXCEPTION: main
                                                                    Process: ie.blogspot.damorton, PID: 5909
                                                                    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ie.blogspot.damorton-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libcocos2dcpp.so"
                                                                        at java.lang.Runtime.loadLibrary(Runtime.java:366)
                                                                        at java.lang.System.loadLibrary(System.java:989)
                                                                        at sonar.systems.framework.SonarFrameworkActivity.<clinit>(SonarFrameworkActivity.java:92)
                                                                        at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                        at java.lang.Class.newInstance(Class.java:1650)
                                                                        at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2545)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
                                                                        at android.app.ActivityThread.access$900(ActivityThread.java:177)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:145)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5951)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:372)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

And this error when I try to set the api level to 21

Did you build the native library first?
The Android build doesn’t do it for you. It only packages the native library in the /libs …

Yes I ran cocos compile -p android --android-studio and then opened it in AS. I have since got it working in Eclipse but its still buggy. Im attempting to use sdkbox now to see if its any better.