Android.mk - app(apk) use c/++ and java libraryWhen you want write an android app that built with Android source, you need create an Android.mk to indicate compiler how to do that.If the app need use c/c++ & java library, the content of Android.mk is listed as below. dir structure :app |- AndroidManifest.xml |- Android.mk |- res |- src |- libs |- XXX.jar |- YYY.so |- Android.mk The first Android.mk content : LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) ############################################################ LOCAL_STATIC_JAVA_LIBRARIES := my-jar-lib LOCAL_MODULE_TAGS := eng user ############################################################ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := DMClient include $(BUILD_PACKAGE) ############################################################ include $(CLEAR_VARS) LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \ my-jar-lib:libs/XXX.jar include $(BUILD_MULTI_PREBUILT) include $(call all-makefiles-under,$(LOCAL_PATH))LOCAL_STATIC_JAVA_LIBRARIES defines the java library.LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES associates the lib name and jar file (represented by relative path) which is contributed by third party.The last line means that includes all Android.mk which locate under the current path. In that way, the second Android.mk listed as below is included. The second Android.mk content : LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_PREBUILT_LIBS := YYY.so include $(BUILD_MULTI_PREBUILT)The first line is important that announce YYY.so located in the current directory . If you didn't declare LOCAL_PATH (the first line), compiler will go to app/ to find XXX.so instead go to app/libs/ to find due to the second Android.mk is included by the first Android.mk. ===================================================== 上述可以编译通过,但不会将*.so文件打包到.apk中,在第一个mk文件中,加入: LOCAL_JNI_SHARED_LIBRARIES := YYY
如果我要用/assets/hello-jni.so这个文件,我如何设置访问路径呢
2. add the so to the build path
3. use System.loadLibrary("xx") to load library.
static{system.loadlibrary("");}
NDK是把原来一些繁琐的东西简单化了一点,
你可以找一下在ndk出现前,工程师们如何手工打包so的文章
dir structure :app
|- AndroidManifest.xml
|- Android.mk
|- res
|- src
|- libs
|- XXX.jar
|- YYY.so
|- Android.mk
The first Android.mk content : LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS) ############################################################
LOCAL_STATIC_JAVA_LIBRARIES := my-jar-lib
LOCAL_MODULE_TAGS := eng user
############################################################ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := DMClient include $(BUILD_PACKAGE) ############################################################
include $(CLEAR_VARS) LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
my-jar-lib:libs/XXX.jar include $(BUILD_MULTI_PREBUILT) include $(call all-makefiles-under,$(LOCAL_PATH))LOCAL_STATIC_JAVA_LIBRARIES defines the java library.LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES associates the lib name and jar file (represented by relative path) which is contributed by third party.The last line means that includes all Android.mk which locate under the current path. In that way, the second Android.mk listed as below is included.
The second Android.mk content :
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_PREBUILT_LIBS := YYY.so include $(BUILD_MULTI_PREBUILT)The first line is important that announce YYY.so located in the current directory . If you didn't declare LOCAL_PATH (the first line), compiler will go to app/ to find XXX.so instead go to app/libs/ to find due to the second Android.mk is included by the first Android.mk.
=====================================================
上述可以编译通过,但不会将*.so文件打包到.apk中,在第一个mk文件中,加入:
LOCAL_JNI_SHARED_LIBRARIES := YYY