Cocos2d-x with Android Studio

Cocos2d-x with Android Studio

I have followed this tutorial to get Cocos2dx working with Android studio. However because there is no official IDE for Cocos2dx with android I do all my coding in Xcode and then I run the cocos command script “cocos compile -s “.\proj.androidstudio” -p android --ndk-mode debug” to compile the android project. The only problem is that my android project is not updated with the changes I made in Xcode. The reason for this is because the file in my android project is not updated. However I can manually add it and the changes are shown.

Are the any plans for this to fixed in the future? I am using Cocos2dx 3.4 and android ndk-r9d. Thanks

You mean the file is not updated when you add files to the an Xcode target?

Well even if you used Android Studio to edit/run your game code, you’d still need to come back to Xcode, and make changes there, in order to compile for iOS/Mac, and then Visual Studio to compile for Win32, so there is never going to be a universal solution to this.

Im running android studio on a mac. So Im doing all the coding in Xcode then running the cocos compile command to compile my the android project. Then I drop the updated file into my android studio project. Anyway you have answered my question by saying there will never be a universal solution

However I would expect to be able to build all of the source from with Android Studio to avoid having to copy files around manually; I believe that cannot happen until 1.3 is release though.

Did you try new cocos2dx 3.7. It has support for android studio

1 Like

Hi @satti , I try cocos2d-x-3.7.1, but don’t know what is the proper way to import. I tried:

  1. Open existing project in Android Studio project > Choose directory (In another attempt, I also tried to choose the base directory MyGame)
  2. Run
  3. Error: couldn’t find “”.

Do you have experienced importing this to Android Studio?

Hi @seraphpl, Did you compile the project with “cocos” before opening in android studio?
You need to compile your project using cocos command.
use the following command to compile android studio project
“cocos compile -p android --android-studio”

Thank you for reply, that error is solved, new error is appear, but I will try to solve it first.
So, every time we want to run we have to use “cocos compile -p android --android-studio”?

Eclipse is your best bet for Android coding.

@SonarSystems using cocos2dx v 3.7, my eclipse project does not build from inside eclipse. Is this the intended behaviour ? When I compile the eclipse project from the command line and open it in Eclipse, the project is corrupted and I cant do anything in it.
How do you use eclipse with cocos2dx v 3.7?

@seraphpl yes you need to compile whenever you made modification in your c++ source you need to run the command (cocos compile)

1 Like

Whats the log saying, what is the problem?

It just not build the project to reflect the changes. After building it from the console and opening eclipse, eclipse says that files were modified outside and hence its reverting to the previous generated version. Also, after a couple of times of doing this, eclipse does not open any c++ file inside the editor.

Could you send us a screenshot of Eclipse

Here are the errors :