安卓8预装可卸载应用
环境
系统:Android 8
CPU:MTK
理论上改法适用于其他平台,比如展讯。
不适用于安卓11。安卓11请参照android 11®预装APP到data/app目录
实现
假设要内置test这个应用。
第一步把test添加到系统编译配置中,不同平台或cpu文件不一样。
比如:
device/mediateksample/xx/device.mk
PRODUCT_PACKAGES += test
然后是创建Android.mk, 这一步很关键,很多种写法都可能要问题。
错误写法1
Adroid.mk有问题的写法
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := testapp
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT)/system/vendor/operator/app
include $(BUILD_PREBUILT)
错误写法2
另外一种写法是针对Android新版本的,在安卓8中不能这么写
LOCAL_MODULE_PATH := $(TARGET_OUT)/system/vendor
这种改法会出错:
Non-symlink out/target/product/xx/system/vendor detected!
You cannot install files to out/target/product/xx/system/vendor while building a separate vendor.img!
错误写法3
使用这个目录也有问题:
$(TARGET_OUT)/system/vendor/operator/app
2023-11-01 08:02:24.012 635-635/system_process I/PackageManager: /vendor/operator/app/xx changed; collecting certs
2023-11-01 08:02:24.174 635-635/system_process W/PackageManager: Failed to scan /vendor/operator/app/test: Failed to collect certificates from /vendor/operator/app/test/test.apk
错误写法4
也不能放data/app/目录下
注意如果这么写,可能会出错
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_PRIVILEGED_MODULE := true
LOCAL_DEX_PREOPT:=false
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
include $(BUILD_PREBUILT)
2023-11-01 08:01:01.132 634-634/system_process W/PackageManager: Failed to scan /data/app/test: Failed to collect certificates from /data/app/xx/text.apk
正确写法
Android.mk要按这样写:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_POST_PROCESS_COMMAND := $(shell mkdir -p $(TARGET_OUT_DATA_APPS)/$(LOCAL_MODULE)
LOCAL_POST_PROCESS_COMMAND := $(shell cp -r $(LOCAL_PATH)/$(LOCAL_MODULE).apk $(TARGET_OUT_DATA_APPS)/$(LOCAL_MODULE)/)
修改PackageManagerService.java,注释掉PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION
否则启动会报这个异常。
diff --git a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
index a4f6eab106..b9f07bf849 100644
--- a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -11795,11 +11795,12 @@ public class PackageManagerService extends IPackageManager.Stub
+ " but expected at " + known.codePathString
+ "; ignoring.");
}
- } else {
+ } /*else {
throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
"Application package " + pkg.packageName
+ " not found; ignoring.");
}
+ //帅得不敢出门 */
}
}
作者:帅得不敢出门 原创文件谢绝转载