How to run test cases on android-ndk

 转载地址:http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_run_test_cases_on_android-ndk#How-to-run-test-cases-on-android-ndk

 

新版cocos2dx配置有稍微的修改,见url:

http://www.cocos2d-x.org/wiki/How_to_build_and_run_HelloWorld_on_Android_NDK_r5_and_above

 

This document describes how to run tests under ndk.
The development environment is windows & cygwin, linux is of course.

1. Set Up Development Environment

This document doesn't describe how to set up the environment for ndk. There is already a good description
on the android social site. The address is:
http://developer.android.com/

There are some attentions below.

1.1 The ndk version must be r4 or r5

ndk-r4 offered by google doesn't support STL, but the engine depends on it, so we should
find a version that supports STL. Luckily, some one has done it. You can download it here:
http://www.crystax.net/android/ndk.php

  • If you would like to build on crystax.net ndk-r4, please follow the steps 1.1.1 ~ 1.1.3
  • If you would like to build cocos2d-x tests on ndk-r5, you can use the default settings in android.mk file, and just jump to 1.2
1.1.1 Change the cocos2dx/Android.mk

replace

# it is used for ndk-r4
# if you build with nkd-r4, uncomment it   
# LOCAL_LDLIBS := -L$(LOCAL_PATH)/platform/third_party/android/libraries \
#                -lGLESv1_CM -llog -lz \
#                -lpng \
#                -lxml2 \
#                -ljpeg \
#                -lskia

# it is used for ndk-r5  
# if you build with ndk-r4, comment it   
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)  
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/platform/third_party/android/libraries) \
                 -lGLESv1_CM -llog -lz \
                 -lpng \
                 -lxml2 \
                 -ljpeg \
                 -lskia

with

# it is used for ndk-r4
# if you build with nkd-r4, uncomment it   
LOCAL_LDLIBS := -L$(LOCAL_PATH)/platform/third_party/android/libraries \
                -lGLESv1_CM -llog -lz \
                -lpng \
                -lxml2 \
                -ljpeg \
                -lskia

# it is used for ndk-r5  
# if you build with ndk-r4, comment it   
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)  
# LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/platform/third_party/android/libraries) \
#                 -lGLESv1_CM -llog -lz \
#                 -lpng \
#                 -lxml2 \
#                 -ljpeg \
#                 -lskia
1.1.2 Change the tests/test.android/jni/tests/Android.mk

Replace

# it is used for ndk-r4
# if you build with nkd-r4, uncomment it   
# LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../libs/armeabi \
#                -lGLESv1_CM \
#                -lcocos2d -lcocosdenshion -llog \
#                -lbox2d -lchipmunk \
#                -L$(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries -lcurl

# it is used for ndk-r5    
# if you build with ndk-r4, comment it   
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)    
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \
                -lGLESv1_CM \
                -lcocos2d -llog -lcocosdenshion \
                -lbox2d -lchipmunk \
                -L$(call host-path, $(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries) -lcurl

with

# it is used for ndk-r4
# if you build with nkd-r4, uncomment it   
LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../libs/armeabi \
                -lGLESv1_CM \
                -lcocos2d -lcocosdenshion -llog \
                -lbox2d -lchipmunk \
                -L$(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries -lcurl

# it is used for ndk-r5    
# if you build with ndk-r4, comment it   
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)    
# LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \
#                -lGLESv1_CM \
#                -lcocos2d -llog -lcocosdenshion \
#                -lbox2d -lchipmunk \
#                -L$(call host-path, $(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries) -lcurl

1.1.3 Change build_native.sh

Set "ANDROID_NDK_ROOT" to the path of ndk-r4

1.2 We use eclipse as the IDE

Use other IDE is ok, but we do not instruct it here.

1.3 The version of cygwin should be 1.7 or above

This is described in google documents.

1.4 The tests can run on 2.0 and above

2. Download source code

Here we suppose you have set up the ndk development environment, and you can run the samples
offered by ndk. If not, you should read the google documents carefully, or you can ask some
kind people. It is easy, don't worry about it.

Now, download source code of ndk-r4 and cocos2dx.
The address of ndk-r4 is:
http://www.crystax.net/android/ndk.php
The address of cocos2dx is:
https://github.com/cocos2d/cocos2d-x

3. Compiling

Change the value of variables ANDROID_NDK_ROOT and COCOS2DX_ROOT, which are defined in
$COCOS2DX_ROOT/tests/test.android/build_native.sh. COCOS2DX_ROOT means the path of cocos2d-x,
it contains directories such as Box2D, chipmunk and so on.

Run build_native.sh to compile native code. If you use windows + cygwin, and do not know how to run it, follow me.

Run cygwin
Enter the directory of Tests/test.android
./build_native.sh

4. Running

Running tests is the same as other ndk samples. We use Eclipse as an example.

4.1 Build Project

This step will generate R.java automatically, it will also compile the java code and
generate the .apk.

4.2 Clean Project

If you recompile the native code and want to pack the .so to .apk, you should do
this step. Step 1 will not pack the .so to .apk except the first time.

4.3 Run Project

Right click the project, select "run as", then select "Android Application". Don't forget to
start your emulator before running.

5. About the resource path

cocos2d-x unzips resource file from .apk at running, so we should set the path of .apk by using
CCFileUtils::setResourcePath(). Because the resource should be putted in specific directory to
packed into .apk, so we put the resource in assets. It is the reason to use CCFileUtils::setRelativePath("assets")
in $COCOS2DX_ROOT/tests/AppDelegate.cpp.

Why not use "assets/Images/xxx.png" in the source code? Becauce the tests code can run in
different platforms, and other platforms such as iOS don't have to put the resource in assets.

6. Warning

6.1 clean project

You should do "clean project" after recompiling native code. If not, the latest .so will not be
packed into .apk.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这些都是 Android NDK 内部的 `Android.mk` 文件。其中,`./android-ndk-r25c/sources/android/native_app_glue/Android.mk` 是用于编译 Native Activity 示例应用程序的 `Android.mk` 文件;`./android-ndk-r25c/sources/android/support/Android.mk` 是包含一些 Android 支持库的 `Android.mk` 文件;`./android-ndk-r25c/sources/android/ndk_helper/Android.mk` 是包含一些辅助函数和类的 `Android.mk` 文件;`./android-ndk-r25c/sources/android/cpufeatures/Android.mk` 是用于编译 `cpufeatures` 库的 `Android.mk` 文件,该库提供了一些 CPU 相关的信息和功能;`./android-ndk-r25c/sources/cxx-stl/llvm-libc++abi/Android.mk` 和 `./android-ndk-r25c/sources/cxx-stl/llvm-libc++/Android.mk` 是用于编译 C++ STL 库的 `Android.mk` 文件,分别对应 libc++abi 和 libc++ 两个 STL 库;`./android-ndk-r25c/sources/third_party/googletest/Android.mk` 是用于编译 Google Test 测试框架的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/shaderc/Android.mk` 是用于编译 Shaderc 编译器的 `Android.mk` 文件,该编译器可以将 GLSL 代码编译成 SPIR-V 代码;`./android-ndk-r25c/sources/third_party/shaderc/libshaderc/Android.mk` 是用于编译 Shaderc 库的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/shaderc/libshaderc_util/Android.mk` 是用于编译 Shaderc Util 库的 `Android.mk` 文件,该库提供了一些辅助函数和类;`./android-ndk-r25c/sources/third_party/shaderc/third_party/Android.mk` 是用于编译 Shaderc 编译器依赖的第三方库的 `Android.mk` 文件,包括 glslang 和 spirv-tools 两个库;`./android-ndk-r25c/sources/third_party/shaderc/third_party/glslang/Android.mk` 是用于编译 glslang 库的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/shaderc/third_party/spirv-tools/Android.mk` 是用于编译 spirv-tools 库的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/vulkan/src/build-android/jni/Android.mk` 是用于编译 Vulkan 库的 `Android.mk` 文件。 如果您要在 Android NDK 中编写自己的 `Android.mk` 文件,可以参考这些示例文件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值