Android Studio support

Android Studio support


Hi all, the github latest codes supports Android Studio. More information can refer to this issue.


You can just use Android Studio to open the folder(such as cocos2d-x/cocos/tests/cpp-tests/, then click the run button to build an run. You can also debug the c++ codes too.


  • Can not use cocos command to compile the Android Studio project, work in progress.
  • Can not view cocos2d-x cpp files in Android Studio which means can not debug engine codes directly, but can step into it. It is the bug of Android Studio, and Google developers said it is fixed in Android Studio 2.3. I haven’t tried it.

You are appreciated to test and report any bug. Thanks.

Android Studio: Build-Run AND Auto Complete?
Android generate apk for two platforms: armeabi-v7a:x86 (split apk)
[Solved] Android NDK: MyGame_shared depends on undefined modules: android_native_app_glue
Strange new problem building to android studio?

@zhangxm is this feature available for Cocos Creator projects?


Will there be a switch to cmake instead of ndkbuild? Any plans on that?


I can view cocos2d-x cpp files in Android Studio 2.2.3. I can debug as well.


@jake72 no, currently Cocos Creator projects doesn’t support it. Will support it later.
@mars3142 we may change to use cmake after refactoring cocos2d-x cmake files.
@piotrros Really? Did you do anything special?


@zhangxm check my post: How to link prebuilt Cocos2D X C++ library to Android Studio project?

It’s a slightly modified configuration from a pull request.

In my case I’m not seeing cocos files (only my own cpp files), because I’m using precompiled version, however at some point I had a version where I could see them, so it’s for sure possible.


Thanks, that works for me in Android Studio 2.3, including debugging. :grinning:


I think we should add a tutorial for beginners in the programmer’s guide.


@piotrros yep, it is needed after fixing cocos command issue.


Could you please include fix for multiple APK(when set in gradle to generate multiple APK with different ABI) , right now cocos command generating multiple APK’s but moving only one of them to main build/release folder, so we need manually go to app/build subfolder and get other generated APK’s. With gradle support it is now common scenario when user generating multiple APK’s at once and cocos should support it by default.


after this supporting, cocos command will invoke gradle to do the compiling things, so it is not an issue.


The issue is not the compiling (different ABI and productFlavors). The issue with the cocos command is the copy of the APK at the end into the build folder.


After this patch, if using cocos command to compile project, it will not copy the APK any more. Did you mean use cocos command to compile project doesn’t support Android Studio)?


@krow i updated Android Studio to 2.3, can not see cocos2d-x c++ source code too. Can you see it?


No, I can only see cocos2d-x Java source code.

The only time I see cocos2d-x c++ source code is if I step into it with the debugger.


Yep, i met the issue.


Strange, can you upload example project, where you can’t see cpp files?


You can just use cocos2d-x v3 branch, and use Android Studio to open tests/cpp-empty-test/ folder.


I’ve updated compileSdkVersion to 25, buildToolsVersion to 25.0.1, gradle version to 2.3.0. I don’t get this “PROP_NDK_NODE” stuff so I’ve removed all if’s in gradle file. Now I can see all cpp files:

Here’s the cpp-empty-test project: (148.6 KB)

[Solved] Prebuilt Libraries - gen-libs & NDK versions
Using prebuilt libs

@piotrros after updating gradle and build tools version, i can see the cpp files now. It is nothing about the ifs. Thanks.