在Android N中签名使用下面的命令就可以了
java -jar signapk.jar platform.x509.pem platform.pk8 app-debug.apk signed.apk
该命令在Android O中会报错。具体错误如下。
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.conscrypt.OpenSSLBIOInputStream.<init>(OpenSSLBIOInputStream.java:34)
at org.conscrypt.OpenSSLX509Certificate.fromX509PemInputStream(OpenSSLX509Certificate.java:129)
at org.conscrypt.OpenSSLX509CertificateFactory$1.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:226)
at org.conscrypt.OpenSSLX509CertificateFactory$1.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:222)
at org.conscrypt.OpenSSLX509CertificateFactory$Parser.generateItem(OpenSSLX509CertificateFactory.java:100)
at org.conscrypt.OpenSSLX509CertificateFactory.engineGenerateCertificate(OpenSSLX509CertificateFactory.java:278)
at java.base/java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:355)
at com.android.signapk.SignApk.readPublicKey(SignApk.java:184)
at com.android.signapk.SignApk.main(SignApk.java:1007)
Caused by: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [conscrypt_openjdk_jni-windows-x86_64, conscrypt_openjdk_jni]
at org.conscrypt.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:176)
at org.conscrypt.NativeCryptoJni.init(NativeCryptoJni.java:49)
at org.conscrypt.NativeCrypto.<clinit>(NativeCrypto.java:53)
... 9 more
错误原因是conscrypt_openjdk_jni-windows-x86_64, conscrypt_openjdk_jni
。,也就是conscrypt_openjdk_jni
。
这里需要libconscrypt_openjdk_jni.so。
libconscrypt_openjdk_jni.so 在源码中存在于2个地方:
1.out/host/linux-x86/lib64
2.prebuilts/sdk/tools/linux/lib64
我这里用的是out/host/linux-x86/lib64下的libconscrypt_openjdk_jni.so 文件,如果1路径下的报错就用2路径下的,大家用的都不一样。
把需要签名的app-debug.apk
,signapk.jar
, platform.x509.pem
,platform.pk8
,libconscrypt_openjdk_jni.so
,放到同一目录下,例如放到vendor/mediatek/proprietary/packages/apps/xxx
,进入xxx目录下后执行下面的命令即可。
java -Djava.library.path=. -jar signapk.jar platform.x509.pem platform.pk8 app-debug.apk app_sign.apk
参考链接:
Android8.1源码下对APK进行系统签名
给一个apk签系统签名
如何获得系统权限--解决no conscrypt_openjdk_jni in java.library.path错误
Android 8.0系统给第三方apk进行系统签名(未使用Andriod Studio,在Android系统编译环境下签名)