I'm using RESTMock for my instrumentation tests, but it only works if I set usesCleartextTraffic
to true
in my manifest. I only want that to be true for instrumentation tests, though. Is there a way to do that?
I tried creating a new manifest file in the androidTest
folder. The tests run but they fail like usesCleartextTraffic
is still 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>
I know that RESTMock supports https starting from version 0.3.2, but I'd rather not have to deal with it. I actually followed their guide and ended up with this error from 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.
Any ideas?
I followed this answer and moved this manifest I created to the debug
source folder and then it worked. Now the android:usesCleartextTraffic="true"
option is only applied to my debug build, which is used by the instrumentation tests, so it works, but it still doesn't feel like the proper solution.
Similar to the App Transport Security (ATS) feature in iOS (see also best practice 6.5 Implement App Transport Security), Android 6.0 and later makes it easier to prevent an app from using cleartext network traffic (e.g., HTTP and FTP without TLS) by adding the android:usesCleartextTraffic attribute to the Android ...
By putting android:debuggable="true" in your manifest file, application will go in debug mode, that means android will manage all logs file regarding your application. But make sure put it again false (or remove this tag) if application will going to live or for release mode.
On Android 9.0 (API level 28) or higher, cleartext support is disabled by default and apps targeting Android 9.0 or higher will need to add the android:usesClearTextTraffic="true" flag in the AndroidManifest. xml file. If you are only working with HTTPS files, this flag is not required.
android:supportsRtl="true" enables support for right-to-left languages. Without this, layout will always be left-to-right, However by itself it does not change the layout to be from right to left. It simply enables other attributes - one of those new attributes controls whether is left-to-right or right-to-left.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With