本文转载自:http://blog.csdn.net/kris_fei/article/details/55100299
Platform: RK3288
OS: Android 6.0
Kernel: 3.10.92
由于项目的apk安装需要shareid为system的权限(不需要高权限的apk是可以正常安装的),
一开始我用的是releasekey,导致签名文件不匹配无法安装,因此就替换系统默认platform签名文件.
生成新的签名文件
方法参考rk3288/build/target/product/security/README
[kris@:~/rk3288]$./development/tools/make_key platform ‘/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com‘
后面参数可自行修改,参见:
http://blog.csdn.net/jscese/article/details/24243171
会生成两种文件:
公钥: platform.x509.pem
私钥: platform.pk8
系统端修改:
不管编译版本(项目需求),都改成platform签名文件.
build/core/Makefile:
ifeq ($(TARGET_BUILD_VARIANT),user)
BUILD_KEYS := release-keys
endif
#Kris, 170214, use our platform key.
+ BUILD_KEYS := platform-keys
build/core/config.mk:
# The default key if not set as LOCAL_CERTIFICATE
ifdef PRODUCT_DEFAULT_DEV_CERTIFICATE
DEFAULT_SYSTEM_DEV_CERTIFICATE := $(PRODUCT_DEFAULT_DEV_CERTIFICATE)
else
DEFAULT_SYSTEM_DEV_CERTIFICATE := build/target/product/security/testkey
endif
#Kris, 170214, use our platform key.
+ DEFAULT_SYSTEM_DEV_CERTIFICATE := build/target/product/security/platform
这样build systemimage就会用名字为platform的签名文件.
APK端:
这里拿Music app作测试.
[kris@:~/rk3288/packages/apps/Music]$ g df
diff --git a/Android.mk b/Android.mk
index d2b7691..c6aa64c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -7,7 +7,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \
src/com/android/music/IMediaPlaybackService.aidl
LOCAL_PACKAGE_NAME := Music
-
+LOCAL_CERTIFICATE := platform
LOCAL_SDK_VERSION := current
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2db6259..2dbd79b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -15,7 +15,9 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.music">
+ package="com.android.music"
+ coreApp="true"
+ android:sharedUserId="android.uid.system">
<original-package android:name="com.android.music" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="9"/>
如果没定义LOCAL_CERTIFICATE, 或者LOCAL_CERTIFICATE的签名和系统签名不一致,安装会不成功,有如下提示:
[kris@ecovacs:~/rk3288/out/target/product/rk3288/system/app/Music]$ adb install Music.apk
4318 KB/s (904296 bytes in 0.204s)
pkg: /data/local/tmp/Music.apk
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]
logcat中会有:
01-21 14:51:37.101 2215 2215 D AndroidRuntime: Calling main entry com.android.commands.pm.Pm
01-21 14:51:37.160 2175 2188 D DefContainer: Copying /data/local/tmp/Music.apk to base.apk
01-21 14:51:37.677 517 572 W PackageManager: Package com.android.music signatures do not match the previously installed version; ignoring!
参考:
http://blog.csdn.net/jscese/article/details/24243171
http://blog.csdn.net/jimbo_lee/article/details/39183831
http://blog.csdn.net/jingwen3699/article/details/8024900
http://blog.csdn.net/jiangwei0910410003/article/details/51316688