How to run HelloWorld and tests on linux

Version 21 (Minggo Zhang, 2011-09-27 23:04)

1 1 Minggo Zhang
h1. How to run HelloWorld and tests on linux
2 1 Minggo Zhang
3 18 Minggo Zhang
cocos2d-x supports linux platform from cocos2d-1.0.1-x-0.9.2.
4 18 Minggo Zhang
This document will describe how to run HelloWorld and tests on linux and android simulator. 
5 1 Minggo Zhang
6 18 Minggo Zhang
The enviroment is ubuntu 11.04 + eclipse3.7. 
7 18 Minggo Zhang
8 1 Minggo Zhang
h2. 1. Set up environment
9 1 Minggo Zhang
10 15 Minggo Zhang
h3. 1.1 get cocos2d-x source code
11 15 Minggo Zhang
12 1 Minggo Zhang
a) get latest code from git, it is not stable
13 18 Minggo Zhang
<pre>git clone https://github.com/cocos2d/cocos2d-x.git</pre>
14 1 Minggo Zhang
b) get released version, it is stable
15 21 Minggo Zhang
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Download
16 15 Minggo Zhang
17 18 Minggo Zhang
h3. 1.2.  install android sdk, use eclipse as IDE
18 15 Minggo Zhang
19 9 Minggo Zhang
Refer the link to install android sdk http://developer.android.com/sdk/index.html
20 8 Minggo Zhang
*Use this appoach to install jdk*
21 1 Minggo Zhang
<pre>
22 1 Minggo Zhang
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
23 1 Minggo Zhang
sudo apt-get update
24 1 Minggo Zhang
sudo apt-get install sun-java6-jdk
25 1 Minggo Zhang
</pre>
26 15 Minggo Zhang
27 15 Minggo Zhang
h3. 1.3. install cdt for eclipse to compile c/c++ codes in eclipse
28 15 Minggo Zhang
29 1 Minggo Zhang
Help -> Install New Software... -> Add...
30 8 Minggo Zhang
!install_cdt.jpg!
31 15 Minggo Zhang
32 11 Minggo Zhang
The link of cdt is http://download.eclipse.org/tools/cdt/releases/helios.
33 15 Minggo Zhang
34 15 Minggo Zhang
h3. 1.4. install ndk
35 15 Minggo Zhang
36 14 Minggo Zhang
You can download ndk here http://developer.android.com/sdk/ndk/index.html
37 14 Minggo Zhang
Because we use ndk standalone toolchain to build android programe, so we should do some work
38 14 Minggo Zhang
<pre>
39 1 Minggo Zhang
# create a "customized" toolchain installation
40 14 Minggo Zhang
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=<your path>
41 1 Minggo Zhang
42 1 Minggo Zhang
# add the environment variable in /etc/profile, because eclispe should use it
43 1 Minggo Zhang
export PATH="$PATH:<your path>"
44 14 Minggo Zhang
</pre>
45 15 Minggo Zhang
46 14 Minggo Zhang
NDK is the root of your ndk, you should change <your path> to your own path.
47 14 Minggo Zhang
More information of ndk standalone toolchain, please refer http://www.srombauts.fr/android-ndk-r5b/docs/STANDALONE-TOOLCHAIN.html
48 15 Minggo Zhang
49 15 Minggo Zhang
h3. 1.5. install needed libs
50 15 Minggo Zhang
51 7 Minggo Zhang
<pre>sudo apt-get install  libgl1-mesa-dev libglfw-dev freeglut3-dev libzip-dev</pre>
52 7 Minggo Zhang
If you meet problem as me, maybe you should run the command before installing the libs
53 7 Minggo Zhang
<pre>sudo apt-get -f</pre>
54 14 Minggo Zhang
55 7 Minggo Zhang
56 7 Minggo Zhang
h2. 2. Run with makefile
57 7 Minggo Zhang
58 20 Minggo Zhang
First, build all libraries
59 20 Minggo Zhang
<pre>
60 20 Minggo Zhang
cd $COCOS2DX
61 20 Minggo Zhang
./build_linux.sh
62 20 Minggo Zhang
</pre>
63 20 Minggo Zhang
COCOS2DX is the root of the cocos2d-x.
64 20 Minggo Zhang
65 16 Minggo Zhang
It is simple to run with makefile
66 16 Minggo Zhang
<pre>
67 16 Minggo Zhang
cd $HELLOWORLD/linux/
68 16 Minggo Zhang
make
69 16 Minggo Zhang
./HelloWorld
70 16 Minggo Zhang
</pre>
71 16 Minggo Zhang
72 1 Minggo Zhang
HELLOWORLD is the root of helloworld, in my environment it is /home/zhangxm/cocos2d-x/HelloWorld.
73 20 Minggo Zhang
You can run tests in the same way. It is simple, isn't it?
74 16 Minggo Zhang
75 7 Minggo Zhang
h2. 3. Run with eclipse
76 12 Minggo Zhang
77 12 Minggo Zhang
First, import existing projects: File -> Import...
78 12 Minggo Zhang
!import_project.jpg!
79 12 Minggo Zhang
80 12 Minggo Zhang
Then select the directory of the root of cocos2d-x
81 12 Minggo Zhang
!select_project.jpg!
82 7 Minggo Zhang
83 13 Minggo Zhang
Now, you can build and run HelloWorld and tests.
84 17 Minggo Zhang
* build
85 17 Minggo Zhang
Right click the project of HelloWorld -> Build Project
86 17 Minggo Zhang
* run
87 17 Minggo Zhang
Right click the project of HelloWorld -> Run as -> Local c/c++ Application
88 2 Minggo Zhang
89 19 Minggo Zhang
You can run tests in the same way.
90 19 Minggo Zhang
91 2 Minggo Zhang
h2. 4. Run on android emulator
92 1 Minggo Zhang
93 17 Minggo Zhang
h3. 4.1 Build .so
94 1 Minggo Zhang
95 17 Minggo Zhang
1. Right click the project of HelloWorld -> Build Configurations -> Set Active -> AndroidDebug
96 17 Minggo Zhang
2. Right click the project of cocos2dx-base -> Build Configurations -> Set Active -> AndroidDebug
97 17 Minggo Zhang
3. Right click the project of CocosDenshion -> Build Configurations -> Set Active -> AndroidDebug
98 17 Minggo Zhang
4. Right click the project of HelloWorld -> Build Project
99 17 Minggo Zhang
100 17 Minggo Zhang
The steps above are compiling libcocos2d.so libcocosdenshion.so and copy these .so into HelloWorld/android/libs/armeabi.
101 17 Minggo Zhang
102 17 Minggo Zhang
h3. 4.2  New android project and run
103 17 Minggo Zhang
104 1 Minggo Zhang
File -> New -> Project -> Android Project
105 1 Minggo Zhang
!new_android_project.jpg!
106 18 Minggo Zhang
107 18 Minggo Zhang
Right click the project of ApplicationDemo -> Run as -> Android Application
108 19 Minggo Zhang
109 19 Minggo Zhang
You can run tests in the same way, the difference are:
110 19 Minggo Zhang
* Build different .so
111 19 Minggo Zhang
1. Right click the project of cocos2dx-test -> Build Configurations -> Set Active -> AndroidDebug
112 19 Minggo Zhang
2. Right click the project of cocos2dx-base -> Build Configurations -> Set Active -> AndroidDebug
113 19 Minggo Zhang
3. Right click the project of CocosDenshion -> Build Configurations -> Set Active -> AndroidDebug
114 19 Minggo Zhang
3. Right click the project of libBox2D -> Build Configurations -> Set Active -> AndroidDebug
115 19 Minggo Zhang
3. Right click the project of libChipmunk -> Build Configurations -> Set Active -> AndroidDebug
116 19 Minggo Zhang
4. Right click the project of cocos2dx-test -> Build Project
117 19 Minggo Zhang
* The path to new android project is cocos2d-x/tests/test.android.