APK簽名報錯

weixin_34357887發表於2018-11-28

使用的jar:$CODE/out/host/linux-x86/framework/signapk.jar

簽名命令1:java -jar signapk.jar platform.x509.pem platform.pk8 Apk_To_Be_sign.apk Apk_Signed.apk

使用命令1簽名報錯:

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.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
        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-linux-x86_64, conscrypt_openjdk_jni-linux-x86_64-fedora, 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)

可以看見報錯說少了[conscrypt_openjdk_jni-linux-x86_64, conscrypt_openjdk_jni-linux-x86_64-fedora, conscrypt_openjdk_jni]

因為這個檔案在prebuilts/sdk/tools/linux/lib64下面,於是使用命令2,多加了-Djava.ibrary.path引數:
java -Djava.library.path=prebuilts/sdk/tools/linux/lib64 -jar signapk.jar platform.x509.pem platform.pk8 Apk_To_Be_sign.apk Apk_Signed.apk

報錯:

FATAL ERROR in native method: RegisterNatives failed for 'org/conscrypt/NativeCrypto'; aborting...
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
        - locked <0x0000000580106818> (a java.util.Vector)
        - locked <0x0000000580143958> (a java.util.Vector)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
        at java.lang.Runtime.loadLibrary0(Runtime.java:870)
        - locked <0x000000058011a438> (a java.lang.Runtime)
        at java.lang.System.loadLibrary(System.java:1122)
        at org.conscrypt.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.conscrypt.NativeLibraryLoader$1.run(NativeLibraryLoader.java:272)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.conscrypt.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:264)
        at org.conscrypt.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:252)
        at org.conscrypt.NativeLibraryLoader.load(NativeLibraryLoader.java:197)
        at org.conscrypt.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:169)
        at org.conscrypt.NativeCryptoJni.init(NativeCryptoJni.java:49)
        at org.conscrypt.NativeCrypto.<clinit>(NativeCrypto.java:53)
        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.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
        at com.android.signapk.SignApk.readPublicKey(SignApk.java:184)
        at com.android.signapk.SignApk.main(SignApk.java:1007)

解決方法

-Djava.ibrary.path引數路徑使用out/host/linux-x86/lib
java -Djava.library.path=out/host/linux-x86/lib -jar signapk.jar platform.x509.pem platform.pk8 Apk_To_Be_sign.apk Apk_Signed.apk
簽名成功!

相關文章