The simplest NDK example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.