Why can't a Flutter application connect to the Internet when installing "app-release.apk"? But it works normally in debug mode
Solution 1
Open the AndroidManifest.xml
file located at ./android/app/src/main
and add the following line:
<manifest xmlns:android="...">
<uses-permission android:name="android.permission.INTERNET"/> <!-- Add this -->
</manifest>
From here:
Add the android.permission.INTERNET permission if your application code needs Internet access. The standard template does not include this tag but allows Internet access during development to enable communication between Flutter tools and a running app.
Solution 2
If you had put
<uses-permission android:name="android.permission.INTERNET"/>
in AndroidManifest.xml
And if it's not working, try checking the connectivity of the device. Mobile data or Wi-Fi on the Android device. Try using the Google Chrome browser for Google Search.
If it's not working, allow
8.8.8.8
in the DNS setting of the computer you are using.
Solution 3
Add this to file android/app/src/main/AndroidManifest.xml after the package name:
<uses-permission android:name="android.permission.INTERNET"/>
bimasakti
Updated on July 08, 2022Comments
-
bimasakti almost 2 years
In debug mode, everything looks good. I get answers and data lists from my API. But after creating app-release.apk and installing it on my phone, there isn't an Internet connection any more.
Here is my code:
ScopedModelDescendant<ReportPosViewModel>( builder: (context, child, model) { return FutureBuilder<List<Invoice>>( future: model.invoices, builder: (_, AsyncSnapshot<List<Invoice>> snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: case ConnectionState.active: case ConnectionState.waiting: return Center( child: const CircularProgressIndicator()); case ConnectionState.done: if (snapshot.hasData) { // Something todo } else if (snapshot.hasError) { return NoInternetConnection( action: () async { await model.setInvoice(); await getData(); }, ); } } }, ); }, ),
-
Soon Santos over 4 yearsNo changes necessary for iOS?
-
CopsOnRoad over 4 years@SoonSantos yes no changes needed for iOS.
-
john over 4 yearsis this necessary for flutter too??it is flutter and not java project,I used this but does not work yet
-
CopsOnRoad over 4 years@john This isn't like Flutter or Java, rather it's for Android. And for an Android project it is necessary to use it.
-
john over 4 yearsI think in debug mode we dont have to use this,but I add it to manifest but still does not work.I tested it last night and it was ok but now it does not work agian!!!
-
Ray Coder about 4 yearsI have put permission in profile. Should i put it in main androidmanifest?
-
CopsOnRoad about 4 years@RayCoder Profile won't do the work for release, you need to put it in a place mentioned in the answer.
-
Rahman Rezaee over 3 yearsI add to manifest internet permission but network not work, I also test in google and other browser it work. just in application not work . but its work in debug and release mode when I get aab not work
-
justin0060 about 3 yearsDid you find a solution for it? @RahmanRezaee
-
Vipin Krishna over 2 yearsJust inserting didn't work for me. Run/debug app required before taking build
-
Imran Zahoor over 2 yearsImportant note:
uses-permission
comes directly undermanifest
but not insideapplication
. Like<manifest...><uses-permission... /><application ...</manifest>
. The official documentation about that can be found over here flutter.dev/docs/development/data-and-backend/networking -
CopsOnRoad over 2 years@ImranZahoor It's already put directly under the
manifest
tag in the answer. -
Imran Zahoor over 2 yearsWhile doing this, it created confusion for me, so shared this, so others can took benefit from it. For me the example shared on flutter link was more clearer :)
-
mekdigital over 2 years<3 try checking the connectivity of the device
-
Marwin Lebensky about 2 yearsI know it's not that relevant, but your closing tag says
maniFAST
instead ofmanifest
. Gotta go FAST! -
CopsOnRoad about 2 years@MarwinLebensky Haha, thanks for pointing that out, I updated the post.