如何解决 no conscrypt_openjdk_jni in java.library.path 的错误?

How to solve no conscrypt_openjdk_jni in java.library.path error?

我想签署我的 apk,所以我执行了以下命令:

java -jar signapk.jar platform.x509.pem platform.pk8 app-debug.apk ~/Desktop/test.apk

但我收到以下错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no conscrypt_openjdk_jni in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at org.conscrypt.NativeCryptoJni.init(NativeCryptoJni.java:25) at org.conscrypt.NativeCrypto.(NativeCrypto.java:54) at org.conscrypt.OpenSSLBIOInputStream.(OpenSSLBIOInputStream.java:34) at org.conscrypt.OpenSSLX509Certificate.fromX509PemInputStream(OpenSSLX509Certificate.java:119) at org.conscrypt.OpenSSLX509CertificateFactory.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:220) at org.conscrypt.OpenSSLX509CertificateFactory.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)

如何解决这个错误?

(openjdk 版本 "1.8.0_141" OpenJDK 运行时环境 (build 1.8.0_141-8u141-b15-3~14.04-b15) OpenJDK 64 位服务器 VM(构建 25.141-b15,混合模式) )

java -Xmx2048m -Djava.library.path="out/host/linux-x86/lib64" \
    -jar out/host/linux-x86/framework/signapk.jar \
    -w build/target/product/security/platform.x509.pem \
    build/target/product/security/platform.pk8 \
    FileNeedSign.apk FileNeedSign_Signed.apk

我正在使用 Jetty、Kotlin、Java 8 和 Maven。我的解决方案是双重的。首先在pom.xml中添加Conscrypt:

<dependency>
    <groupId>org.conscrypt</groupId>
    <artifactId>conscrypt-openjdk</artifactId>
    <version>2.2.1</version>
    <classifier>linux-x86_64</classifier>
</dependency>

请注意 <classifier> 需要适合您的操作系统。从这里的列表中选择一个:https://github.com/google/conscrypt/

我喜欢将我的配置放在代码中。如果你喜欢,请点燃我。我按照此处的说明进行操作:https://www.eclipse.org/jetty/documentation/current/configuring-ssl.html#conscrypt 所以在设置 Jetty 的 sslContextFactory 之前,我必须添加:

    Security.addProvider(new OpenSSLProvider())

然后之后:

    // SSLv2Hello and SSLv3 are outdated and insecure.
    // TLSv1.3 works with Conscrypt, but not Java 8!
    sslContextFactory.setExcludeProtocols("SSLv2Hello", "SSLv3", "TLSv1.3")
    sslContextFactory.setProvider("Conscrypt");

我认为这就是解决问题的原因。我今天做了很多改变。

我有一个单独的问题,即我的本地主机 SSL 证书无效。我从这个开始: 但最终从服务器获取证书并编辑我的 /etc/hosts 文件以使 localhost 看起来像那个服务器。