系统签名是让客户做的系统app可以正常在我们系统上运行,你的app要写成系统app,再系统签名才有意义。
说明:固件中app需要在源码中编译,而不使用IDE编译,然后copy到/system/app/*目录,是因为app需要使用系统的权限,在AndroidManifest.xml中申明了系统权限
android:sharedUserId="android.uid.system"。
1、单独签名解决方案,文件放置在同一个文件夹signapk目录下
在Android源码目录build/target/product/security/,找到平台签名文件:platform.pk8和platform.x509.pem。
在Android根目录android/prebuilts/sdk/tools/lib找到签名工具:signapk.jar。
把签名证书“platform.pk8 ”“platform.x509.pem ”,签名工具“signapk.jar ”放置在同一个文件夹signapk;
执行命令:java -jar signapk.jar platform.x509.pem platform.pk8 Demo.apk signedDemo.apk // Demo.apk代表签名前apk,signedDemo.apk代表签名后apk
如果出现报错:
zwei@ubt144c:/work/zwei/czd/3399_qianming/security$ java -jar signapk.jar platform.x509.pem platform.pk8 BDService_17082811.apk BDService_17082811_sign.apk
Exception in thread "main" java.lang.UnsatisfiedLinkError: no conscrypt_openjdk_jni in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at org.conscrypt.NativeCryptoJni.init(NativeCryptoJni.java:25)
at org.conscrypt.NativeCrypto.<clinit>(NativeCrypto.java:54)
at org.conscrypt.OpenSSLBIOInputStream.<init>(OpenSSLBIOInputStream.java:34)
at org.conscrypt.OpenSSLX509Certificate.fromX509PemInputStream(OpenSSLX509Certificate.java:119)
at org.conscrypt.OpenSSLX509CertificateFactory$1.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:220)
at org.conscrypt.OpenSSLX509CertificateFactory$1.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:216)
at org.conscrypt.OpenSSLX509CertificateFactory$Parser.generateItem(OpenSSLX509CertificateFactory.java:94)
at org.conscrypt.OpenSSLX509CertificateFactory.engineGenerateCertificate(OpenSSLX509CertificateFactory.java:272)
at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
at com.android.signapk.SignApk.readPublicKey(SignApk.java:182)
at com.android.signapk.SignApk.main(SignApk.java:1087)
则找到 libconscrypt_openjdk_jni库:prebuilts/sdk/tools/linux/lib64/libconscrypt_openjdk_jni.so
把它拷贝到文件夹signapk目录下,然后执行以下语句:
java -Djava.library.path=. -jar signapk.jar platform.x509.pem platform.pk8 BDService_17082811.apk BDService_17082811_sign.apk
2、直接在Android SDK编译环境签名方案
直接在Ubuntu编译环境执行(input.apk表示签名前apk,output.apk表示签名后apk)
java -jar out/host/linux-x86/framework/signapk.jar -w build/target/product/security/platform.x509.pem build/target/product/security/platform.pk8 device/rockchip/rk3399/preinstall/input.apk device/rockchip/rk3399/preinstall/output.apk