Android studio and c++ sources

Android studio and c++ sources



I’m porting some old Cocos2D / Objective-C projects to Cocos2D-X / C++

I can compile the iOS version and get everything working smoothly, but when I try to use Android studio I get lost.

  1. Where are my .h and .cpp files? I browsed all the subfolders in the left panel but I couldn’t find any of them.

  2. Is it true that the simulator doesn’t work at all? Do I need and android device in order to test my apps?
    (Can't get CPP game to compile or run for android)

  3. Is there a better IDE for Android? Maybe Eclipse?
    (I’m not an Android expert nor do I like Java, so I am a newbie in Android development.)

thank you




  1. There should be a Folder named like your Game Title. Expand it. In this Folder Structure you will find cpp->MyGame->Classes. There you will find all header and source files.

  2. The Simulators work fine. Just create one with the AVD-Manager. Your PC/Mac should have enough memory. otherwise it will be slow. Testing on Device is faster/better. I would recommend to use real Devices for testing purpose.

  3. Eclipse is no longer supported by Google. So Android Studio is the way you have to go. At first I preferred xcode too (I also started with IOS)… but Android Studio now has the same quality.

  1. In plz make sure to have this lines:


And rebuild.

  1. You’re on a Mac? In my iMac, Android Emulators doesn’t works. It was impossible for me.

  2. I trust in Google. Android Studio.


thank you

there is not a Classes folder :frowning:


Thank you

I added those lines but I still can’t see the cpp sources

This is my left panel

a lot of Gradle stuff
I can find my assets, but no code at all…


I wouldn’t use wildcards for cpp files, but headers are fine. I use often one header and platform specific implementations (eg. class.h, class-android.cpp, class-ios.cpp, class-macos.cpp, class-windows.cpp and class-linux.cpp). Do you have a good solution for that, without moving the cpp files outside of the Classes folder? Because I have to add new files manually in XCode/Visual Studio, I also can add them to CMakeList for Android and Linux as well.


I will try dragging the Classes folder into the panel.

By the way, I read that I should write down the .h and .cpp files names into some configuration file, is that true?


Dragging the cpp files into the left panel doesn’t seem to be working :rofl:

I’m a on mac running El Capitan; Cocos2d-x version is 3.14.1; Android studio version is 3.2.1.

I read the it is possible to compile from the terminal using this command

cocos compile -p android --android-studio

I get this error: ANDROID_SDK_ROOT not defined. Please define it in your environment.

(I don’t think it is related to the missing Classes subdirectory issue)

If I hit the play button on Android studio it opens up the simulator (I grabbed a Nexus I think) but the app doesn’t work (It’s a fresh new cocos project)


I added this lines to the bash_profile

export ANDROID_SDK_ROOT=/Users/{{your user}}/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/{{your user}}/.android/avd

When I run the app in the simulator it keeps crashing, if I try to compile via terminal I get this new error:

The directory 'android-13' can't be found in ANDROID_SDK_ROOT/platforms, please use --ap to set needed API level

I will try to build it on a real android device but I don’t have any…


maybe you should create a clean (default) project with cocos-console. for testing purpose.

You could try to add Andoid sdk and ndk location in project setting. right click
YourGameTitle in the treeView and choose “Open Module Settings”. In the left menu select “SDK Location” and set the correct paths for sdk and ndk.
Don’t forget to download missing sdk versions and dependencies (SDK Manager).

In your case Android Studio has not fully synced you project
After successfully syncing and building you will see cpp-files in the file-tree. At least you will see a “cpp” Folder and cpp-files that came with cocos2d-x. Next step would be to edit to add your own cpp-Files to your Project (but thats the next step).


Thank you

Every time I create a new project, Android studio complains about the gradle version and a missing line (google()) in some configuration files.
I fix that adding google() in build.gradle
then I follow these instructions:

I sync and I get these errors:

Could not find lint-gradle-api.jar (
Searched in the following locations:

but if I set this gradle-thing to 3.2.1 it seems to be working and I just get this warning:

WARNING: Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.

The SDK and NDK paths are set properly

Is it possible that, in order to get Android studio working with Cocos2D-X, I have to install Android studio and the SDKs first and Cocos only after they are set?

:joy: I used to think that XCode configuration and its plist file were a mess…


You can also use “Open Module Settings” (for your Game) to change/view your Gradle Settings. Just select “project” in the left menu panel.
If have cocos2dx 3.17 and the following Gradle Version:

Gradle Version: 4.4
Android Plugin Version: 3.1.4
Android Plugin Repository: google(), jcenter
Default Library Repository: google(), jcenter

So if you like you can change to v4.4 in (Gradle Version)


Then you have to replace every “compile” with “implementation”.
Look in the treeView under “Gradle Scripts” there is a build.gradle (Module: YourGameTitle).
At the bottom of this file is dependencies { … }. replace all “compile” with “implementation”.
you right click your project and again open module settings. Select your Game Module and open the dependencies. there are dropdowns for ever external lib… select implementation for every lib and you it’s done!
If you have included all needed dependencies then syncing will not fail anymore.

If some versions of libs or sdk’s are incompatible Android Studio will prompt you to update… wait until syncing is done or Android Studio prompts you to update something.

good luck :slight_smile:


Thanks again

before I give it a try I want to re-install Cocos2dx and give the correct paths when asked.

The installation process asks for the NDK_ROOT
I pasted what it seems to be the path /Users/mandarx/Library/Android/sdk/ndk-bundle
Then it asks for the ANT_ROOT which I don’t know what it is (now I do)
But I don’t have any Apache Ant library installed.

Is it a prerequisite for Android developing with Android studio?


I installed ANT and re-installed Cocos2D-X. I created a new project but I still can’t see any cpp source nor does the app run on the simulator.


Made everything but it won’t work.

Thank you.