Below in Ubuntu compile a C language Hello World and run on an Android phone or simulator
Go to program location
CD ~/pnp5/jni
There are three files main.c android.mk, application.mk, Contents:
$ cat main.c #include <stdio.h>int main (void) { printf ("Hello World"); return 0;} ~/pnp5/jni$ Cat Android.mk local_path:= $ (call My-dir) include $ (clear_vars) local_src_files:= main.clocal_module: = Pnp5local_module_tags: = Optionalinclude $ (build_executable) ~/pnp5/jni$ cat application.mk APP_ABI: = All
Note: Application.mk can not (how you only need arm program)
Run Ndk-build in the current directory
(If there is no ndk, go to download one)
~/pnp5/jni$ ~/android-ndk-r10d/ndk-build[arm64-v8a] compile:pnp5 <= main.c[arm64-v8a] Executable:pnp5[ar M64-V8A] install:pnp5 = libs/arm64-v8a/pnp5[x86_64] compile:pnp5 <= main.c[x86_64] Executable : pnp5[x86_64] install:pnp5 = libs/x86_64/pnp5[mips64] compile:pnp5 <= Main.c[mips64] Executable : pnp5[mips64] install:pnp5 = libs/mips64/pnp5[armeabi-v7a] Compile thumb:pnp5 <= main.c[armeabi-v 7a] executable:pnp5[armeabi-v7a] install:pnp5 = Libs/armeabi-v7a/pnp5[armeabi] Compile thumb:pnp5 &L t;= Main.c[armeabi] Executable:pnp5[armeabi] install:pnp5 = libs/armeabi/pnp5[x86] Compile:pnp 5 <= main.c[x86] executable:pnp5[x86] install:pnp5 = libs/x86/pnp5[mips] COMPILE:PNP5 <= Main.c[mips] executable:pnp5[mips] INSTALL:PNP5 = LIBS/MIPS/PNP5
Discover a program that generates various target types in the Libs directory at the same level as JNI.
Running on the emulator (real machine)
Use ADB devices to check if Android is booting
With ADB push PNP5 data/
Use the ADB shell to enter the device, and then run CD data; chmod 777 pnp5;./pnp5
Hello World Prints it out.
The simplest NDK example