How to run cpp-tests on Android

How to run cpp-tests on Android

Environment Requirements

We will be using OS X in this example. The process on Win32 and Linux is more or less the same.

Prerequisite

Download Cocos2d-x

Download cocos2d-x and unzip it. We could simply unzip it on the root directory of your home folder. After unzipping, double click the cocos2d-x folder and you should have a structure like this:

Download JDK, SDK and NDK

For developing Android games Java is a must have toolkit.

  • check your Java version.
java -version
  • Hopefully you see results similar to: (although your version may be slightly different.)
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

The bundle includes the newest Android SDK version plus an Eclipse version with Android Development Tool included. This is all you need.

After downloading it, unzip the package at ~/AndroidDev directory. The folder contains two folders: *sdk* and *eclipse*.

You can launch Eclipse and install other SDK versions, if needed. Here is an example:

  • Download NDK. Always use the latest version. This article version is r9d.

After downloading it, unzip the package at the same location of the Android SDK. In our case, it is under the *~/AndroidDev* directory.

Verify Your Environment
  • verify that *Python 2.7* is installed and it is accessible:

    python --version in your Terminal (or cmd on Win32) and it will give you the following result:

$ python --version
Python 2.7.5
  • If not, you need to download and install Python before proceeding.

    Hombrew brew install python

    Python.org

  • Install and verify Apache Ant

    Hombrew brew install ant

    Apache.org

  • verify that Ant is found, simply execute:

$ ant
Buildfile: build.xml does not exist!
Build failed
Setup Environment Variables
  • Run setup.py to configure your Android development environment. This will set the necessary environment variables needed. If you haven't configured this environment before, you will be prompted to enter paths for variables that are not found.

    Caution: You must not use the ~ sign. Use the full path to your home directory. Otherwise, the scripts will fail due to error path value.

  • In your cocos2d-x directory runpython setup.py and you will get the following results:

setuppy01

*COCOS2D_CONSOLE_ROOT* environment variable to point to the bin directory under ~/cocos2d-x/tools/cocos2d-console directory.

*NDK_ROOT* environment variable to point to the location of where you put the NDK. (i.e android-ndk-r9d/)

*ANDROID_SDK_ROOT* environment variable to point to the location of where you put the adt-bundle. Example /Users/guanghui/AndroidDev/adt-bundle-mac-x86_64-20130522/sdk/. The adt-bundle-mac-x86_64-xxxx, the xxxx number maybe different. So please note this non-trival difference.

*ANT_ROOT* environment variable to point to the location of where you put apache-ant-x.x.x. The apache-ant-x.x.x, the x.x.x number maybe different. So please note this non-trival difference.

When all environment variables are correctly configured, you should let them take effect.

On *nix systems, you could issue the following commands:

source ~/.bash_profile

on win32 system, you can just close the command line windows and restart it.

Use android-build.py to build cocos2d-x samples
  • Change your directory to the where the android-build.py script is located. (usually cocos2d-x/build)
cd build

and then

android list targets

Notice the id in this next screen shot.

Now I can execute:

python android-build.py -p 19 cpp-tests

That's it! The script will handle everything else that you need. When finished you should get the following message:

buildsuccess

How to deploy it on your Android phone via command line
  • Enable USB Debugging on your phone and then connect your phone via USB.

  • Change your directory to the the bin directory of testcpp android project:

cd ~/cocos2d-x/tests/cpp-tests/proj.android/bin

(Note:If your current directory is build, you could use some relative path like thiscd ../tests/cpp-tests/proj.android/bin)

  • Then you could use adb to install the apk to your android phone:
adb install TestsDemo-debug.apk
  • If it prompts you that adb is not a command, you must re-equery your ~/.bashrc file. Ensure it contains the 4 environment variables set above. You could also manually execute:
 export PATH=$PATH:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools
  • You should see the following screenshot! You are done.

runsuccess

Troubleshootings
  • After configuring the setup.py file, you still suffer NDK_ROOT not found issue, you maybe missed executing source ~/.bash_profile.

  • If you are on Windows pc, you should be careful about the difference of the filesystem conventions.

setuppy01.png (53.4 kB) owen, 2014-04-01 09:14

setuppy02.png (68.9 kB) owen, 2014-04-01 09:14

setuppy03.png (92.1 kB) owen, 2014-04-01 09:14

buildandroidpy.png (131.3 kB) owen, 2014-04-01 09:14

buildsuccess.png (56 kB) owen, 2014-04-01 09:14

cocos2dxdirectory.png (19.5 kB) owen, 2014-04-01 09:14

donwloadSDK.png (91.8 kB) owen, 2014-04-01 09:14

runsuccess.png (33.3 kB) owen, 2014-04-01 09:14

android-list-targets.png (40.3 kB) slackmoehrle, 2014-05-07 21:59

android-list-targets1.png (54.8 kB) slackmoehrle, 2014-05-07 22:22

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值