I am developing a Flutter app that works perfectly on iOS in both production and debug modes. However, I am encountering an issue with the Android version of the app. The problem is that HTTP calls to my REST API are blocked when the app is downloaded from the Play Store’s internal test plan. The same app works perfectly in debug mode and also when built directly on my phone.
Error Message:
ClientException with SocketException Connection failed (OS Error: Operation not permitted, errno = 1), address XXXXXXXX, port 5050,, uri http://XXXXXXXXXX:5050/Auth/SignUp
Steps Taken:
Added android:usesCleartextTraffic="true" to the AndroidManifest.xml:
I added the following line to the AndroidManifest.xml file to allow cleartext traffic:
<application
android:usesCleartextTraffic="true">
Verified Network Configuration:
I checked my build.gradle files and ensured that there are no restrictions that could be blocking the HTTP traffic.
Tested Different Scenarios:
-
The app works correctly when built directly on the device in release mode.
-
The app works correctly when run in debug mode.
-
The issue only occurs when the app is installed from the Play Store internal test track.
It’s been 2 days that I’m struggeling with this and my app need to be in production very soon…
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="mobilitizzz_mobile"
android:name="${applicationName}"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
3
Answers
Well, after a lot of research and investigations I turns out that the issues was related to this line that was currently only in debug manifest:
I just added it in android/app/main/AndroidManifest.xml like so
Starting with Android API 28 and iOS 9, these platforms disable insecure HTTP connections by default.
With this change Flutter also disables insecure connections on mobile platforms. Other platforms (desktop, web, etc.) are not affected.
Try this:
In your project’s android directory
app/src/main/res/
create new directory calledxml
. And createnetwork_security_config.xml
in it.network_security_config.xml:
Now add this in your
AndroidManifest.xml
file:I have recently face the same issue and this works for me. I hope it works for you.
For more Information: Insecure HTTP connections are disabled by default on iOS and Android.
Just Add One line in you AndroidManifest.xml