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

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

@milos1290 your link is broken

We have a video tutorial on this https://www.youtube.com/watch?v=gdOkbXYsf04&index=9&list=PLRtjMdoYXLf7fqFlzHJvfhBgO0ddEm-k5

@SonarSystems That’s a great video, thank you! (also for all the other video you made)

I just started developing with Cocos, so at many things I’m still trying to figure out how to do it. The biggest question I currently have is whether it is possible to step-through-debug Cocos Code with Android Studio. I guess it is not, so I’m currently thinking about using Visual Studio, running the proj.win32 Code (which is beautifully debuggable) and once in a while have a look on an actuall smartphone device. What is your thought on that workflow?

I would use Android studio only for running and use another IDE of your choice for development and debugging.

Thank your for your fast respond. I will try it out.

I’m looking forward to a great collaboration with everyone in this forum!

That’s how I work. I spend 95% of my time in VS, then just do the OS specific stuff in XCode, Eclipse or Android studio.

I like to work in Linux some time too, but I’ve not found an IDE that compares to Visual Studio, so I’ve got to stick with Windows for now :stuck_out_tongue:

I’d quite like to setup Visual Studio to do my Android and iOS builds, but I’ve not looked into how hard it is to setup yet. Has anyone tried it with Cocos2D-X?

When you say I’d quite like to setup Visual Studio to do my Android and iOS builds,, are you saying you want to actually build and run iOS and Android from VS?

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.