将APK升级为系统应用
一个apk想要成为系统应用,需要满足以下条件
- 将APK安装到内存卡,而不是SD卡
- 将用户角色设置为系统用户
- 将APP设置为桌面应用,这样可以保证能够开机启动和后台运行
- 使用和系统镜像同样的签名证书,对APK进行签名
- 通过镜像修改工具,将APK文件拷贝到镜像中的预安装目录
将APK安装到内存卡
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="internalOnly">
</manifest>
将用户角色设置为系统用户
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="android.uid.system">
</manifest>
将APK设置为桌面应用
这一步不是必须的,取决于你是否想应用开机自启动,并且一直在后台运行
<!-- Activity -->
<activity
android:name="com.android.app.board.upgrade.biz_activity.HomeActivity"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
对APK进行系统签名
系统镜像签名文件,是编译系统镜像时指定的
但好在,大多定制ROM,用的都是Google官方镜像的默认证书,不会自己去改证书
到此网站,可查看安卓各个版本的源码
进入版本号/build/target/product/security目录
下载里面的platform.pk8和platform.x509.pem这两个签名文件
将签名文件、用于签名的jar包、要签名的apk,放到同一目录,执行以下批处理代码
cd %~dp0
java -jar signapk.jar platform.x509.pem platform.pk8 1.apk 2.apk
pause
签名工具和6.0.1的系统签名文件可以从这里下载
拷贝APK到系统目录
可下载镜像编辑工具DragonFace,直接将APK添加为系统APP
也可以手动执行ADB指令,来将APK文件拷贝priv-app系统目录
下次机器重启时,就会自动安装该APK文件,并将其作为系统应用
adb remount
adb push 2.apk /system/priv-app