How to create and run a Cocos2d-x project from Android Studio

Cocos2d-x projects are created using the cocos command line tool, which is included with  cocos2d-x. To create a cocos2d-x project, first navigate to the directory where you want the project to be created, then run the following:

cocos new projectname -p com.companyname.projectname -l cpp -d . [-t binary]

Note: I couldn’t get the -t binary flag to work.

The -t  binary option uses pre-built libraries, if you have them, to make the first compilation faster.

After the project is created, navigate into its directory and compile it for Android Studio:

cocos compile -p android --android-studio --ap targetapi

The created Android Studio project (located at can then be imported into Android Studio and run on an applicable Android device.


  • Not upgrading the gradle plugin for the project (which Android Studio asks after importing) led to an exception when running the application.
  • Running the application on a virtual emulator didn’t work, but an actual Android device did.
  • The Classes folder can be edited in Android Studio by opening the directory of the project (not, but the app needs to be run through after compiling through cocos.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s