How to Build an Android Project with Eclipse
Environment Requirements
- A Supported OS (Ubuntu 12.10+, OS X 10.7+, Windows 7+)
- Cocos2d-x v3.0 (https://github.com/cocos2d/cocos2d-x/)
- JDK/SDK 1.6+
- NDK r9d+
- Apache Ant
- Python 2.7.5
- Eclipse with ADT Bundle
- Completed Tutorial (How to run cpp-tests on Android)
We will be using OS X in this example. The process on Win32 and Linux is more or less the same.
Prerequisite
- Completed Tutorial (How to run cpp-tests on Android)
Once completed:
Open the proj.android project with Eclipse.
-
Launch Eclipse
-
Right click your mouse at the empty area of the
Package Explorer
and chooseImport...
. -
Choose
Existing Android Code Into Workspace
from the pop up dialog and ClickNext
.
- Click the
Browse...
button to choose the directory of Cpp-Tests'proj.android
. and Click Ok.
Before choosing the proj.android
directory:
After choosing the proj.android
directory:
- Click Finish.
If all the above processes are correct, the Finish
button will be enabled and you should click it.
Import Libcocos2dx Project
This is more or less the same process as we do in the previous section except for the path of the proj.android
is different.
The path of the libcocos2dx project is [your own game project folder]/cocos/2d/platform/android/java
.
(Note:Here you must select the project right under your own project!!)
Build and Run the Android Project
-
Connect your Android phone with
USB remote debugging
option enabled. -
Make sure your computer can recognize your phone (you might need to install drivers for your specific phone)
-
Right Click The
CppTests
project and chooseRun as...
->Android Application
.
Build an Empty Project Created with the cocos
command
Build it with the cocos command
(Note this might not be the same as the previous section, but you can do it by navigating to the proj.android directory and run the build_native.py scripts.)
We could use cocos run -s ~/MyCompany/MyGame -p android
command instead of the python scripts. You could refer to this document for more information.
Open the proj.android project with Eclipse
It's exactly as the process we do in the previous example, above.
Import the Libcocos2dx Project
It's exactly as the process we do in the previous example, above.
Build and Run the Android Project
It's exactly as the process we do in the previous example, above.
TroubleShootings
-
If you get errors in the Eclipse when you imported the Android project. Don't worry, just import the libcocos2dx project will get ride of it.
-
If you imported all the projects and the errors remains, you might need to build the libcocos2dx project manually and to see whether there is a libcocos2dx.jar file under the
bin
directory. -
If you installed the project in your Android phone but it crashed when launching. You should make sure there is a
libxxx.so
file under thelibs/armeabi
directory.