Pages

Monday, September 9, 2013

Cross Compile C for Android

Download NDK
http://developer.android.com/tools/sdk/ndk/index.html


Create Folders and Files
mkdir jni
mkdir libs
mkdir obj

jni/hello.c
#include <stdio.h>
int main(int argc, char **argv)
{
        printf("HelloWorld\n");
        return 0;
}


jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# module names
 LOCAL_MODULE    := hello_world
# list of C files for compiler
 LOCAL_SRC_FILES := hello.c
#build executables
include $(BUILD_EXECUTABLE)


Build
android-ndk-r9/ndk-build

Binary for android is located within obj/local/armeabi/hello_world .