1. Configure Environment VariablesAdd the Make tool PATH environment variable:
E:\Android\android-ndk-r10b\prebuilt\windows-x86_64\bin
2. Write Hello worldNew HELLO.C
#include <stdio.h>int main (intChar* argv[]) { printf (" Hello android!\r\n"); return 0 ;}
3. Write the makefile file as follows
#ndk根目录NDK_ROOT=e:\android\android-ndk-r10b# Compiler root directory toolchains_root=$ (ndk_root)/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64# Compiler directory Toolchains_prefix=$ (toolchains_root)/bin/arm-linux-androideabi# Header File search path Toolchains_include=$ (toolchains_root)/lib/GCC/arm-linux-androideabi/4.6/include-fixed#sdk root directory platfrom_root=$ (ndk_root)/platforms/android- -/arch-arm#sdk Header File search path Platfrom_include=$ (platfrom_root)/usr/INCLUDE#SDK Library File search path Platfrom_lib=$ (platfrom_root)/usr/lib# file name Modale_name=hello# Delete rm=del# Compile Options flags=-i$ (toolchains_include)-i$ (platfrom_include)-l$ (platfrom_lib)-nostdlib-LGCC-bdynamic-lc# all obj files Objs=$ (modale_name). O $ (platfrom_lib)/CRTBEGIN_DYNAMIC.O $ (platfrom_lib)/CRTEND_ANDROID.O #编译器链接all: $ (toolchains_prefix)-GCC$ (FLAGS)-C $ (modale_name).o $ (modale_name). O $ (toolchains_prefix)-GCC$ (FLAGS) $ (OBJS)-o $ (modale_name) #删除所有. o File Clean: $ (RM)*. o# Installer to phoneInstall: ADB push $ (modale_name)/data/local/tmp adb Shellchmod 755/data/local/tmp/$ (modale_name) adb shell/data/local/tmp/$ (modale_name) #运行程序run: adb shell/data/local/tmp/$ (Modale_name)
4. Use the make command to compile the program
generate a target file that can execute a file Hello hello.oSo there are commands to compile the NDK:
//compiling the target filee:\android\android-ndk-r10b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc-ie:\android\android-ndk-r10b/toolchains/ arm-linux-androideabi-4.6/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.6/include-fixed-ie:\android\android-ndk-r10b/platforms/android- -/arch-arm/usr/include-le:\android\android-ndk-r10b/platforms/android- -/arch-arm/usr/lib-nostdlib-lgcc-bdynamic-lc-c hello.c-o hello.o//compile to execute filee:\android\android-ndk-r10b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc-ie:\android\android-ndk-r10b/toolchains/ arm-linux-androideabi-4.6/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.6/include-fixed-ie:\android\android-ndk-r10b/platforms/android- -/arch-arm/usr/include-le:\android\android-ndk-r10b/platforms/android- -/ARCH-ARM/USR/LIB-NOSTDLIB-LGCC-BDYNAMIC-LC hello.o e:\android\android-ndk-r10b/platforms/android- -/ARCH-ARM/USR/LIB/CRTBEGIN_DYNAMIC.O e:\android\android-ndk-r10b/platforms/android- -/arch-arm/usr/lib/crtend_android.o-o Hello
5. Running the programYou can also use makefile
Install and run our program with make installuse make run to run our program install and run can be understood as custom functions in Makefile
I erase the code of the note to the blog garden can not be used
From for notes (Wiz)
Write NDK Hello World purely by hand