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 proj.android-studio) 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 proj.android-studio), but the app needs to be run through proj.android-studio after compiling through cocos.