I have had some issues getting requests from the Android emulator to interact with FireBase. I ended up setting:
android:usesCleartextTraffic="true"
in the manifest file.
A quick search tells me that this allows insecure connections:
Android 6.0 introduced the `useCleartextTraffic` attribute under the application element in the android manifest. The default value in Android P is “false”. Setting this to true indicates that the app intends to use clear network traffic
What do I have to do in order to deploy my application without setting android:usesCleartextTraffic="true"
?
1条答案
按热度按时间z0qdvdin1#
Option 1
In the
res/xml/
folder create anetwork_config.xml
file that contains the following:I believe that
10.0.0.2
is the ip address that the emulator uses on the Android device. If I am wrong, you can update the ip address to whatever might be the correct address.Then in the
AndroidManifest.xml
file in the application tag addandroid:networkSecurityConfig="@xml/network_config"
. The output would look like this:This should allow any traffic coming from an emulator be allowed in clear text, but block other endpoints from being accessed over http/cleartext.
Option 2
You could hypothetically configure a setup with gradle to release a different manifest for debug and release builds. I just looked at the android folder for flutter and what you could do instead is go to the ${PROJECT_FOLDER}/android/app/src/debug/AndroidManifest.xml and add the following:
Your output
AndroidManifest.xml
in the debug folder (which should only be applied to debug builds, may look something similar to this:Note
I haven't tested option 2 myself, but from my understanding, this should work. This medium article may help.