2009年6月18日星期四

Android.mk - app(apk) use c/++ and java library

When 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.

沒有留言:

張貼留言