想内置应用到/data/用户区,让其可卸载
系统android 8(O)
android 11可查看另外一篇《android 11®预装APP到data/app目录》
测试过的平台:MTK
如果发现不管怎么改都无效,请静下心来,clean一次把out删除再试一下,有些时候错误的编译残留会导致怎么改都无效.
假设是添加myapplication.apk到sdk中的, 烧录后要装到/data/区(注意此方法恢复出厂后app会消失)
在PRODUCT_PACKAGES下添加myapplication
PRODUCT_PACKAGES += myapplication
# ifneq ($(strip $(FEATURE_BN_NOT_BUILD_APP)),true)
LOCAL_PATH := $(call my-dir)
LOCAL_MODULE := myapplication
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
# copy apk to /data/app
$(shell mkdir -p $(TARGET_OUT_DATA_APPS)/app/$(LOCAL_MODULE))
$(shell cp $(LOCAL_PATH)/$(LOCAL_SRC_FILES) $(TARGET_OUT_DATA_APPS)/app/$(LOCAL_MODULE))
# endif
这种写法不需要额外在mk中处理so库,默认在apk包中是自带库的,在设备启动过程会自动解压到data下的相应目录中.
diff --git a/base/services/core/java/com/android/server/pm/PackageManagerService.java b/base/services/core/java/com/android/server/pm/PackageManagerService.java
index 238a70f6..f380a66e 100644
--- a/base/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/base/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -12095,11 +12095,11 @@ public class PackageManagerService extends PackageManagerServiceExAbs
+ " but expected at " + known.codePathString
+ "; ignoring.");
}
- } else {
+ } /*else {
throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
"Application package " + pkg.packageName
+ " not found; ignoring.");
- }
+ }*/
}
}
这里列个Android.mk可能错误的写法:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed
LOCAL_MODULE := myapplication
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_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
include $(BUILD_PREBUILT)
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) 由这行来控制安装到data/app下。
这种写法,编译后,在out目录下能搜索到myapplication.apk,但是烧录到设备后,启动找不到这个app
运行过程出错:Failed to scan /data/app/: Failed to collect certificates from xxx
设备会自动删除app
把out下的apk拷贝出来用adb install命令也装不了,
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from /data/app/vmdl1194648165.tmp/base.apk: META-INF/CERT.SF indicates /data/app/vmdl1194648165.tmp/base.apk is signed using APK Signature Scheme v2, but no such signature was found. Signature stripped?]
可见编译过程apk被改动了。
建议data的apk中自带lib,如果依赖/system/lib/下的库,
则需要设置成/data/app下apk可访问/system/lib/下的对应库,否则运行会崩溃出错:
java.lang.UnsatisfiedLinkError: dlopen failed: library “/system/lib/libmmkv.so” needed or dlopened by “/system/lib/libnativeloader.so” is not accessible for the namespace “classloader-namespace”
diff --git a/core/libnativeloader/native_loader.cpp b/core/libnativeloader/native_loader.cpp
index 809160c..d3af503 100644
--- a/core/libnativeloader/native_loader.cpp
+++ b/core/libnativeloader/native_loader.cpp
@@ -102,7 +102,7 @@ static constexpr const char* kVendorClassloaderNamespaceName = "vendor-classload
// (http://b/27588281) This is a workaround for apps using custom classloaders and calling
// System.load() with an absolute path which is outside of the classloader library search path.
// This list includes all directories app is allowed to access this way.
-static constexpr const char* kWhitelistedDirectories = "/data:/mnt/expand";
+static constexpr const char* kWhitelistedDirectories = "/data:/mnt/expand:/system/lib";
static bool is_debuggable() {
char debuggable[PROP_VALUE_MAX];
作者:帅得不敢出门 原创文章谢绝转载收录