客户给了一个内置他们自己apk的需求,定制到Rom里,我们需要在编译系统源码的时候配置好相关的文件即可将apk一起打包到ROM里面,下面我们就来一起打包apk到系统
首先需要在 device/mediatek/common/device.mk 配置如下语句
$(call inherit-product-if-exists, vendor/公司名/product/您的命名.mk)
在mk文件里面配置需要内置的apk label
eg:
#apps
PRODUCT_PACKAGES += \
BDDataPlan\
Facebook\
MultiLingBengaliPlugin\
Multilingkeyboard\
SHAREit\
Skype\
Viber\
WPSOffice\
WST_WAL_C
配置好之后还需要导入 apk文件并且配置宏,就写一个例子吧,也在这个文件夹下写
路径:vendor\公司名\ThirdpartyApps\
配置如下mk文件,没有的自己创建
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.java
添加:
+ 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个后台
首先需要在 device/mediatek/common/device.mk 配置如下语句
$(call inherit-product-if-exists, vendor/公司名/product/您的命名.mk)
在mk文件里面配置需要内置的apk label
eg:
#apps
PRODUCT_PACKAGES += \
BDDataPlan\
Facebook\
MultiLingBengaliPlugin\
Multilingkeyboard\
SHAREit\
Skype\
Viber\
WPSOffice\
WST_WAL_C
配置好之后还需要导入 apk文件并且配置宏,就写一个例子吧,也在这个文件夹下写
路径:vendor\公司名\ThirdpartyApps\
配置如下mk文件,没有的自己创建
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.java
添加:
+ 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个后台