客戶給了一個內置他們本身apk的需求,定製到Rom裏,咱們須要在編譯系統源碼的時候配置好相關的文件便可將apk一塊兒打包到ROM裏面,下面咱們就來一塊兒打包apk到系統java
首先須要在 device/mediatek/common/device.mk 配置以下語句android
$(call inherit-product-if-exists, vendor/公司名/product/您的命名.mk)git
在mk文件裏面配置須要內置的apk labelweb
eg:app
#apps PRODUCT_PACKAGES += \ BDDataPlan\ Facebook\ MultiLingBengaliPlugin\ Multilingkeyboard\ SHAREit\ Skype\ Viber\ WPSOffice\ WST_WAL_C
配置好以後還須要導入 apk文件而且配置宏,就寫一個例子吧,也在這個文件夾下寫code
路徑:vendor\公司名\ThirdpartyApps\server
配置以下mk文件,沒有的本身建立blog
LOCAL_PATH := $(call my-dir) # include $(CLEAR_VARS) LOCAL_MODULE := BDDataPlan LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := Facebook LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := MultiLingBengaliPlugin LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := Multilingkeyboard LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := SHAREit LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := Skype LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := Viber LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := WPSOffice LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) # include $(CLEAR_VARS) LOCAL_MODULE := WST_WAL_C LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app #LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/thirdparty_apps LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT)
工做算是完成了一半,接下來還須要修改frameworks下的java文件,讓內置的三分apk可卸載等操做索引
/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.javaget
添加:
+ final File thirdpartyAppDir = new File(Environment.getRootDirectory(), 「/vendor/thirdparty_apps」);
+ scanDirLI(thirdpartyAppDir, PackageParser.PARSE_IS_SYSTEM
+ | PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags, 0);
添加:
+ private static boolean isThirdpartyApp(int parseFlags) {
+ return (parseFlags & PackageParser.PARSE_IS_THIRDPARTY_APP) != 0;
+ }
public static int PackageParser.PARSE_IS_THIRDPARTY_APP = 1<<11;
修改:
+ if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg) && !isThirdpartyApp(parseFlags)) {
不知道在那行的,能夠搜索關鍵字,ctrl+L 索引行
修改完以後編譯工程,發現如下異常:
No rule to make target `vendor/rmt/ThirdpartyApps/WST_WAL_C.apk', needed by `out/target/product/rmt8382_tb_l/obj/APPS/WST_WAL_C_intermediates/package.apk'. Stop
檢查了下配置文件,發現客戶提供的apk文件跟咱們的mk衝突了,因而修改
WST_WAL_C.APK 爲 WST_WAL_C.apk
從新編譯工程,完美運行
最終效果,內置9個apk,7個可見,2個後臺