分类: Android平台
2013-08-15 09:27:24
1、 在activity1和activity2里分别声明native c
例如:activity1.java里
private native String StringFromActivity1Jni();
static
{
System.loadLibrary("activity1");
}
Activity2.java里
private native String StringFromActivity2Jni();
static
{
System.loadLibrary("activity2");
}
2、 生成 .h文件
用命令:javah -classpath bin/classes/ -jni com.myprj.uitest.activity1和javah -classpath bin/classes/ -jni com.myprj.uitest.activity2 生成activity1和activity2里的头文件
需要特别注意的是红色部分,一定要存在。可以进入工程目录bin/classes路径下查看。如果不能在jni下生成,那就mv吧。
3、 编写Android.mk文件:
LOCAL_PATH := $(call my-dir) //只能有一个这个路径
include $(CLEAR_VARS)
LOCAL_MODULE := activity1
LOCAL_C_INCLUDES += $(LOCAL_PATH) \
$(LOCAL_PATH)/android
LOCAL_SRC_FILES := activity1.c
LOCAL_LDLIBS := -L$(LOCAL_PATH) -lm -lz -llog
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := activity2
LOCAL_C_INCLUDES += $(LOCAL_PATH) \
$(LOCAL_PATH)/android
LOCAL_SRC_FILES := activity2.c
LOCAL_LDLIBS := -L$(LOCAL_PATH) -lm -lz -llog
include $(BUILD_SHARED_LIBRARY)
需要注意的是:include $(BUILD_SHARED_LIBRARY)是生成动态库,也可以生成静态库include $(PREBUILT_STATIC_LIBRARY)
4、 编译:
ndk-build