How can I use Android Studio together with cocos2d-x? Any hints?

Yeah. It’s a new feature of Visual Studio 2015. You can build Windows Phone, Android and iOS. It even has its own Android Emulator.

I think it still requires a Mac with XCode running on your network to compile the iOS code, but it’d still be nice to do everything from the same tool.

That’s very interesting, defo will try this.

You’ll have to make a video if you figure out how to get it working with Cocos2D-X. I’ve found your videos very useful :smile:

Android studio support should work with new gradle experimental plugin which claims to offer full NDK support


and Android Studio 1.3+ (which includes JetBrains’ CLion, a C++ IDE). However I wasn’t able to configure it to recognize cocos2d-x, I keep getting linker errors while building the project (“no such file or directory spine/BoneData.h” etc). I’ll keep trying and, if succeed, will publish a github repository with sample project.

I was able to get at least basic C++ highlighting and navigation by creating symbolic links to cocos2d and Classes directories (this of course only works for Linux and Mac):

$ cd proj.android-studio/app/jni
$ ln -s ../../../Classes
$ ln -s ../../../cocos2d

I compile the native code using cocos command line interface

$ cd proj.android-studio/
$ cocos compile -pandroid --android-studio --no-apk --app-abi x86

and run the app from Android Studio. Not the ideal workflow but at least I can edit all C++ code and java code from a single Android Studio project. One can go even further and configure a pre-build rule in Android Studio to execute the above cocos command before every build automatically.

2 Likes

We may have to :smiley:

It’s Great a suggestion. Do you have a suggestion for auto run and compile cocos compile ? Thanks @denisk20 it’s really help

@arief_platk

  1. Create a new External Tool configuration in Android studio (File -> Other Settings -> Default Settings -> Tools -> External Tools, then click + at the bottom). Assuming that you have cocos command-line tool installed, fill in the form similar to this:

  2. Go to Run -> Edit Configurations, then select your runtime configuration, scroll to the bottom to reveal “Run After” table, click +, select Run External Tool, then select external tool that you have created on step 1:

Now every time you run your configuration you will run cocos build too. Haven’t fully tested it so maybe some tweaks are required.

3 Likes

Thanks @denisk20 this was a big help. I did have to use $ProjectFileDir$ vs $ModuleFileDir$ in order to get CppTests to compile with Android Studio.

Hi,can i debug c++ on android studio?

@yixiaoqingyuz Currently I think you can’t, but it should become possible once they finish full NDK support in Experimental plugin. The steps from post #34 won’t be necessary then.

I thought android studio had full NDK debug support by now - am I wrong?

But running console “cocos” command from android studio is just a shortcut. You can use any text editor and just run it straight from console. It’s not the solution we need. For now I write all code in xcode and just run android app from console.
What’s important it should use gradle, which does all the job. Then we can easily use multidex or import parts of google-play-services (like admob) not whole library. These days hitting 65k method dalvik limit is very easy. Also we should be able to use ndk debugging. Then I guess we can also create a “template” for android studio, so it’ll even be able to create cocos2d-x projects (but that’s not necessary important).

Have a look to my post.

I am trying to build cocos2dx using gradle and full NDK support. Any help would be very apreciated.

Do I have to run the compile command from the proj.android directory? I usually run the compile command from the root of all proj.x (x being the platform) folder. You seem to have run it from the proj.android directory.

I compile the android project with the following command:

$ cocos compile -p android --android-studio

is this different from the one that you have written?

$ cocos compile -pandroid --android-studio

Does Android Studio recognize the cocos2dx classes and methods after creating symbolic links? I am new to cocos2dx. Without code suggestion I am totally blind and much more prone to making errors :frowning:

You should be able to do everything inside Android Studio if you wish. I’ll review this thread as I started writing an Android Studio install doc. http://slackmoehrle.github.io/installation/Android-Studio/

But does android studio allow users to edit the .cpp files with code-completion support?

Yes! Android Studio is built on top of, among other things, CLion, a C/C++ IDE from Jet Brains, which includes C/C++ syntax highlighting. The main problem that people are facing (including me) here is to configure it properly…

After a few months of fighting with Android Studio, C++ and NDK support I said “whatever” and just use command lines to build and deploy everything.

I edit all of my Android C++ in Visual Studio, and use a VS “External Tool” to call the Android Studio scripts. I am doing almost all Cocos2d-x development, so most of the work is in C++ with only occasional Java. I find having a C++ project for iOS, Android, Linux and Mac OS X to be the easiest way to organize the code and build files.

2 Likes

I gave up after a few hours :wink: