Outdated Docs > How to create android project with script

How to create android project with script

This document decribes how to create android projects through batch files (using Windows) or shell scripts (using Linux or Mac).
The script exists on version 0.8.2.

Since version cocos2d-1.0.1-x-0.12.0, you can create a project that supports lua, chipmunk or box2d. The usage is:
* windows
Edit create-android-project.bat, add [~~b|—box2d] at the last of endlocal & _CYGBIN—login “_CYGSCRIPT” _CURRENTDIR _PROJECTNAME _NDKROOT _PACKAGEPATH “windows”.
For example, you want to create a project supports lua, you can add parameters like this:
<pre>
endlocal & _CYGBIN—login “_CYGSCRIPT” _CURRENTDIR _PROJECTNAME _NDKROOT _PACKAGEPATH “windows”~~l
or
endlocal & _CYGBIN—login “_CYGSCRIPT” _CURRENTDIR _PROJECTNAME _NDKROOT _PACKAGEPATH “windows” —lua

</pre>
If you want create a project supports lua and box2d, you can add parameters like this:

endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% "windows" -l -b
or
endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% "windows" --lua --box2d
  • linux On linux, you can pass parameters when you run create-android-project.sh. The usage is <pre> cd \$COCOS2DX_ROOT ./create-android-project.sh [~~b|—box2d] </pre> h2. 1. Under windows Run create-android-project.bat to create an android project. The bat file should be invoked under the root of cocos2dx. Change some macros in create-android-project.bat to work in your environment. * set CYGBIN=F:The path of cygwin bin \ set*ANDROIDTOOLS=D:~~sdk\tools The path of android sdk tools
  • set _NDKROOT=E:-ndk-r4-crystax The root of ndk

In order to create an android project, you should input the package path, target id and project name.

1-1

1.1 Target id

If you don’t know the meaning of target id, you should use android.bat list targets to obtain a list of available targets.
Or you should read the article: http://developer.android.com/guide/developing/tools/android.html
The target ids are different in different environment, you should be sure to input valid target id. As of this writing, cocos2dx currently supports
Android 2.1-update1, Android 2.2 and Android 3.0. Other versions have not been tested.

1.2 Project name

The .bat file will create a directory named “project name” under the root of cocos2dx. The default activity will also be named, “project name”.
In picture 1-1, we have inputted “test” as the project name, making the directory look like:

1-2

1.3 Package path

The package path is the package name of the java file which implement the start activity. In the example, it inputs “org.cocos2dx.example”,
so the test.java lies in test/android/src/org/cocos2dx/example. The package name also used in AndroidMenifest.xml.

The package path should be unique all over the world, or your app may be overridden by another Android app. It is customary, not only in Android development, but in Java development as well, to use your domain name, reversed. If your domain name is google.com, you would normally use com.google as your package path.

1.4 Build project

Run build_native.sh which is under test/android to build the native code (C/C++ code).

1-3

2. Under linux/mac

Change some macros in create-android-project.sh to work in your environment.
* NDK_ROOT=“/workspace/android-dev/android-ndk-r5”
The root of ndk
* ANDROID_SDK_ROOT=“/workspace/android-dev/android-sdk-mac_86”
The root of android sdk

Run create-android-project.sh to create android project. The file should be invoked under the root of cocos2dx.

In order to create an android project, you should input the package path, target id and project name. They have
the same meaning as under windows(refer 1.1 and 1.2). The approach of building project is the same as under windows(refer 1.4).

Important Note
If you get a “Permission denied!” error when running any of the shell scripts, you can try to remedy this by using the chmod command. For example, if you cannot run the @bu

build.jpg (49.1 kB) zhangxm, 2011-03-23 06:03

input.jpg (115.7 kB) zhangxm, 2011-05-20 02:23

directory_view.jpg (32.5 kB) zhangxm, 2011-05-20 02:23

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.