Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android &引用;没有此类供应商:BCJSSE“;升级到OkHttp 4.7.0或更高版本后使用Robolectric时_Android_Okhttp_Robolectric - Fatal编程技术网

Android &引用;没有此类供应商:BCJSSE“;升级到OkHttp 4.7.0或更高版本后使用Robolectric时

Android &引用;没有此类供应商:BCJSSE“;升级到OkHttp 4.7.0或更高版本后使用Robolectric时,android,okhttp,robolectric,Android,Okhttp,Robolectric,我有一些测试,它们使用OkHttp来验证一些服务器调用结果,并使用RobolectrictTestRunner运行 将okhtp库从4.6.0版升级到其上的任何版本后,我无法实例化OkHttpClient,失败原因如下: java.security.NoSuchProviderException: no such provider: BCJSSE 我已经阅读了OkHttp,但找不到任何与Bouncycastle相关的更改,我怀疑这与崩溃有关,或者任何与此问题相关的内容 当作为Junit4测试运

我有一些测试,它们使用
OkHttp
来验证一些服务器调用结果,并使用
RobolectrictTestRunner
运行

okhtp
库从4.6.0版升级到其上的任何版本后,我无法实例化
OkHttpClient
,失败原因如下:

java.security.NoSuchProviderException: no such provider: BCJSSE
我已经阅读了OkHttp,但找不到任何与
Bouncycastle
相关的更改,我怀疑这与崩溃有关,或者任何与此问题相关的内容

当作为
Junit4
测试运行测试时,而不是
RobolectrictTestRunner
,一切正常,但我依靠robolectric为我的实际测试提供不易模仿的功能,因此我必须继续使用它

我正在使用

  • 机械分子4.3.1
  • 安卓工作室4
  • Android Gradle插件3.5.0
更新OkHttp依赖项时崩溃的原因是什么?我们可以做些什么来解决这个问题

复制问题的最小代码段:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import okhttp3.OkHttpClient;

@RunWith( RobolectricTestRunner.class )
public class TestClass {

  @Test
  public void test() {
    OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build();

    //do the actual teststuff
  }
}
堆栈跟踪:

java.security.NoSuchProviderException: no such provider: BCJSSE

    at sun.security.jca.GetInstance.getService(GetInstance.java:83)
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:206)
    at javax.net.ssl.TrustManagerFactory.getInstance(TrustManagerFactory.java:183)
    at okhttp3.internal.platform.BouncyCastlePlatform.platformTrustManager(BouncyCastlePlatform.kt:41)
    at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:237)
    at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:222)
    at path.to.my.class.TestClass.test(TestClass.java:12)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:546)
    at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:252)
    at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
java.security.NoSuchProviderException:没有这样的提供程序:BCJSSE
位于sun.security.jca.GetInstance.getService(GetInstance.java:83)
位于sun.security.jca.GetInstance.GetInstance(GetInstance.java:206)
位于javax.net.ssl.TrustManagerFactory.getInstance(TrustManagerFactory.java:183)
在okhttp3.internal.platform.BouncyCastlePlatform.platformTrustManager(BouncyCastlePlatform.kt:41)
在okhttp3.OkHttpClient(OkHttpClient.kt:237)
在okhttp3.OkHttpClient(OkHttpClient.kt:222)
在path.to.my.class.TestClass.test(TestClass.java:12)处
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:498)
位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:59)
位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:56)
位于org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
位于org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
在org.roblectric.roblectricttestrunner$HelperTestRunner$1.evaluate上(roblectricttestrunner.java:546)
位于org.roblectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:252)
位于org.roblectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
在java.util.concurrent.FutureTask.run(FutureTask.java:266)处
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
运行(Thread.java:748)

OkHttp使用安全提供商的注册来告诉我们要使用哪个平台实例。由于Android和Android Studio中的不兼容更改,该代码最近发生了更改

研究机器人分子代码,他们只注册了两个必要的提供者中的一个

你应该能够通过自己注册来解决这个问题

    Security.insertProviderAt(BouncyCastleProvider(), 1)
    Security.insertProviderAt(BouncyCastleJsseProvider(), 2)
    Security.insertProviderAt(BouncyCastleProvider(), 1)
    Security.insertProviderAt(BouncyCastleJsseProvider(), 2)