Skip to content
Search

Cocos2dx:Android

lastmod 2018-08-17created 2017-11-103 edits

Notes on how to start an Android project using Cocos2dx.

Environment variables

First, the following environment variables need to be set.

  • COCOS2DX_ROOT: Cocos2dx root directory.
  • CYGWIN: Cygwin ROOT directory. (The directory containing the Cygwin.bat file)
  • ANDROID_SDK: Android SDK ROOT directory.
  • ANDROID_NDK: Android NDK ROOT directory.

Integrating Cocos2dx with Eclipse and ADT

  1. After installing the SDK, create a project using the create-android-project.bat file.
  2. The Classes, proj.android, and Resources directories are created.
    1. Copy all files in Classes to proj.android/jni. After copying, edit the proj.android/jni/Android.mk file accordingly.
    2. Copy all files in Resources to proj.android/assets.
  3. Launch Eclipse and import proj.android as an Android project.
  4. Right-click the project > Android Tools > select Add Native support..., then have it generate the library as libgame.so. (android-ndk-r8e does not require Cygwin.)
  5. Copy the sources in COCOS2DX_ROOT/cocos2dx/platform/android/java/src to proj.android/src of the newly created project.
  6. Remove all entries under Eclipse's Project > Properties > Android > Library Reference.
  7. For compiling the additional modules in proj.android/jni/Android.mk to work properly, the NDK_MODULE_PATH environment variable must be set. (In addition, this corresponds to the $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx) $(call import-module,extensions) part.)
    1. Edit the contents of Project > Properties > C/C++ Build > Builder Settings > Build command:.
    2. ndk-build "NDK_MODULE_PATH=COCOS2DX_ROOT;COCOS2DX_ROOT/cocos2dx;COCOS2DX_ROOT/cocos2dx/platform/third_party/android/prebuilt"

The directories required for this project are listed below.

  • COCOS2DX_ROOT/cocos2dx
  • COCOS2DX_ROOT/CocosDenshion
  • COCOS2DX_ROOT/extensions
  • COCOS2DX_ROOT/external

Troubleshooting

Unknown host operating system

On Windows, the following error message may appear.

ERROR: Unknown host operating system

In this case, change the Build command from ndk-build ... to ndk-build.cmd ....

See also

Favorite site

References


  1. Create_android_cocos2dx_project.pdf ↩