2011年4月13日 星期三

[Android] NDK: Link to static library.

Situation:
I got a static library for develop android application incuding header file (lib.h) and static library file (lib.a).
But, I have no idea about how to use this stuff in NDK.
Finally I work it out...

Slove:
I show my code below

My native code (Native.c):

#include <jni.h>
#include "lib.h"      
// include header file

jint Java_com_example_Init( JNIEnv* env, jobject thiz )
{
    Result = Init();   // this is lib.Init()   

    return Result;
}

My make file (Android.mk):
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := lib.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE    := Native
LOCAL_SRC_FILES := Native.c
LOCAL_STATIC_LIBRARIES := mylib
include $(BUILD_SHARED_LIBRARY)

As you see, you have to prebuilt static library into module "mylib" then lick mylib to Native.c.

沒有留言:

張貼留言