13

我正在使用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"选项仅适用于我的调试版本,由仪器测试使用,因此它可以工作,但它仍然不是正确的解决方案。

4

1 回答 1

5

For me the solution is to add a simple AndroidManifest.xml in androidTest/AndroidManifest.xml. This is also mentioned in the answer you reference, but in that case it didn't work because old tooling didn't merge this AndroidManifest.xml.

So, inside androidTest directory, and next to java directory, I have the following:

~/source/my-library/src/androidTest develop*
❯ ls
AndroidManifest.xml java

With this AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.mypackage.mylibrary">

    <application
        android:usesCleartextTraffic="true" />

</manifest>
于 2019-01-08T10:59:41.287 回答