Example code for compiling Android NDK under Linux command line

  • 2021-10-25 07:52:33
  • OfStack

In the past few days, I have been thinking about writing an Runtime of Android to speed up HTML5 Canvas, so that GameBuilder+CanTK can not only develop quickly, but also run close to native applications. So spent some time to study Android NDK, the information on the Internet is about the compilation method in IDE, here records the compilation method under the command line, for the reference of friends in need.

Take compiling hello-gl2 as an example:

0. Install Android NDK/SDK and set the PATH variable (adjust for specific situation)


PATH=$PATH:/work/android/android-sdk-linux/platform-tools/:/work/android/android-sdk-linux/tools/
PATH=$PATH:/work/android/android-ndk-r8/build/tools:/work/android/android-ndk-r8/
export PATH

1. Create a new project with android


cd /work/android/android-ndk-r8/samples
android create project -n Hello -p hello -a Main -k com.hello -t 1

The purpose of creating this project is to produce the files required for ant compilation:


build.xml 
local.properties 
project.properties

2. Now that you need to compile the NDK example, copy these files to the corresponding directories. Compile hello-gl2 here:


[lixianjing@lixianjing samples]$ cp hello/build.xml hello-gl2/
[lixianjing@lixianjing samples]$ cp hello/local.properties hello-gl2/
[lixianjing@lixianjing samples]$ cp hello/project.properties hello-gl2/

3. Then compile, first compile the native code with ndk-build, and then produce apk with ant debug.


[lixianjing@lixianjing hello-gl2]$ ndk-build 
[lixianjing@lixianjing hello-gl2]$ ant debug

Summarize


Related articles: