我正在使用RESTMock进行仪器测试,但它只有在我的清单中设置usesCleartextTraffic
为时才有效。true
不过,我只希望这对于仪器测试是正确的。有没有办法做到这一点?
我尝试在文件夹中创建一个新的清单文件androidTest
。测试运行但它们usesCleartextTraffic
仍然失败false
。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package">
<application android:usesCleartextTraffic="true" />
</manifest>
我知道RESTMock 从0.3.2 版本开始支持https,但我宁愿不必处理它。我实际上遵循了他们的指南,并从 OkHttp3 中得到了这个错误:
java.lang.AssertionError: java.security.NoSuchAlgorithmException: The BC provider no longer provides an implementation for KeyPairGenerator.RSA. Please see https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html for more details.
有任何想法吗?
编辑:
我遵循了这个答案并将我创建的这个清单移到了debug
源文件夹,然后它就可以工作了。现在该android:usesCleartextTraffic="true"
选项仅适用于我的调试版本,由仪器测试使用,因此它可以工作,但它仍然不是正确的解决方案。