对于Android系统集成有源码的第三方库和程序,只需要提供Android.mk文件,把源码集成到 Android编译系统中就可以了,并且有很多例子可以参考。但是对于没有源码的pre-build第三方库和程序,网上介绍的比较少,可以参考的例子也不多。本文简单介绍一下集成pre-build库和程序时候,怎样编写Android.mk。
1、集成静态库 [xhtml] view plaincopyprint?
- 1: LOCAL_PATH := $(call my-dir)
- 2: include $(CLEAR_VARS)
- 3:
- 4: LOCAL_PREBUILT_LIBS := libA.a /
- 5: libB.a
- 6:
- 7: LOCAL_STATIC_LIBRARIES := libA /
- 8: libB
- 9:
- 0: include $(BUILD_MULTI_PREBUILT)
1: LOCAL_PATH := $(call my-dir) 2: include $(CLEAR_VARS) 3: 4: LOCAL_PREBUILT_LIBS := libA.a / 5: libB.a 6: 7: LOCAL_STATIC_LIBRARIES := libA / 8: libB 9: 10: include $(BUILD_MULTI_PREBUILT)
2、集成动态库 [c-sharp] view plaincopyprint?
- 1: LOCAL_PATH := $(call my-dir)
- 2: include $(CLEAR_VARS)
- 3:
- 4: LOCAL_PREBUILT_LIBS := libA.so
- 5: libB.so
- 6: include $(BUILD_MULTI_PREBUILT)
1: LOCAL_PATH := $(call my-dir) 2: include $(CLEAR_VARS) 3: 4: LOCAL_PREBUILT_LIBS := libA.so 5: libB.so 6: include $(BUILD_MULTI_PREBUILT)
3、集成可执行程序
[xhtml] view plaincopyprint?
- 1: LOCAL_PATH := $(call my-dir)
- 2: include $(CLEAR_VARS)
- 3:
- 4: LOCAL_SRC_FILES := hellovprc.elf
- 5: LOCAL_MODULE := hellovprc.elf
- 6: LOCAL_MODULE_CLASS := EXECUTABLES
- 7: LOCAL_MODULE_TAGS := debug
- 8: include $(BUILD_PREBUILT)
1: LOCAL_PATH := $(call my-dir) 2: include $(CLEAR_VARS) 3: 4: LOCAL_SRC_FILES := hellovprc.elf 5: LOCAL_MODULE := hellovprc.elf 6: LOCAL_MODULE_CLASS := EXECUTABLES 7: LOCAL_MODULE_TAGS := debug 8: include $(BUILD_PREBUILT)
4、集成pre-build Android应用程序(APK) 如何集成没有源码的apk文件,纯粹的apk呢?
方法一、目录结构vendor/BM/APPs/MobileQQ2011/MobileQQ2011.apk
vendor/BM/APPs/MobileQQ2011/Android.mk
以下是Android.mk:
[xhtml] view plaincopyprint?
- LOCAL_PATH := $(call my-dir)
- include $(CLEAR_VARS)
- # Module name should match apk name to be installed.
- LOCAL_MODULE := MobileQQ2011
- LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
- LOCAL_MODULE_CLASS := APPS
- LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
- # LOCAL_MODULE_TAGS := user
- #add by yue @20110516
- #you can choose apk's diff location
- # LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
- LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
- LOCAL_CERTIFICATE := platform
- #end
- include $(BUILD_PREBUILT)
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Module name should match apk name to be installed. LOCAL_MODULE := MobileQQ2011 LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) # LOCAL_MODULE_TAGS := user#add by yue @20110516 #you can choose apk's diff location # LOCAL_MODULE_PATH := $(TARGET_OUT_APPS) LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) LOCAL_CERTIFICATE := platform#end include $(BUILD_PREBUILT)
加进去后,在根目录下执行:make即可,
可以在installed-files.txt中查看是否加入到了对应的img文件中。
弊端是如果加入很多apk,要逐个建立这样的目录结构,也因为有android.mk,会产生相应的临时文件
方法二、纯粹拷贝apk文件
目录结构vendor/BM/APPs/MobileQQ2011.apk
vendor/BM/APPs/Renren_Android_3.0.2.apk
。。。。。
通过android提供的PRODUCT_COPY_FILES这个变量来自动拷贝,只需要给此变量赋值。在任何一个确定加入编译的mk文件
中加入(我的是加在msm7627_qrd.mk)
PRODUCT_COPY_FILES += /
vendor/bm/APPS/MobileQQ2011.apk:system/app/MobileQQ2011.apk/
vendor/bm/APPS/Renren_Android_3.0.2.apk:system/app/Renren_Android_3.0.2.apk
这种相对不会很繁琐,不需要一级级的建立目录,在内置很多apk是比较方便。
附加说明: 关于android.mk中的LOCAL_OVERRIDES_PACKAGES需要说明一下,
此变量可以使其他的模块不加入编译,如源码中DeskClock的android.mk有
LOCAL_OVERRIDES_PACKAGES := AlarmClock
使 AlarmClock不会加入到编译系统中,不会生成 AlarmClock.apk。
原先我是死活不明白会什么有两个闹钟 AlarmClock和 DeskClock ,源码几乎相同,原先只在 AlarmClock中的文件中修改,就是没有效果,测试说没有修改,原来发布的版本中只有DeckClock.apk,我却在本地make AlarmClock编译出了AlarmClock.apk,>_
试了一下在 DeskClock的android.mk中加入LOCAL_OVERRIDES_PACKAGES := Calendar,删掉 Calendar.apk, 然后全部make一下,在system/app下calendar.apk竟然没再生成了????!!!
p.s
# Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
# Filter out (do not install) any overridden packages.
overridden_packages := $(call get-package-overrides,$(modules_to_install))
ifdef overridden_packages
# old_modules_to_install := $(modules_to_install)
modules_to_install := /
$(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), /
$(modules_to_install))
endif
其他参考: 1.对Android.mk文件中变量做了详细说明
http://www.cnblogs.com/leaven/archive/2011/03/30/1999350.html
2. Android.mk文件语法规范
http://apps.hi.baidu.com/share/detail/15447104