Why can't a Flutter application connect to the Internet when installing "app-release.apk"? But it works normally in debug mode

67,524

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"/>
Share:
67,524
bimasakti
Author by

bimasakti

Updated on July 08, 2022

Comments

  • bimasakti
    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
    Soon Santos over 4 years
    No changes necessary for iOS?
  • CopsOnRoad
    CopsOnRoad over 4 years
    @SoonSantos yes no changes needed for iOS.
  • john
    john over 4 years
    is this necessary for flutter too??it is flutter and not java project,I used this but does not work yet
  • CopsOnRoad
    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
    john over 4 years
    I 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
    Ray Coder about 4 years
    I have put permission in profile. Should i put it in main androidmanifest?
  • CopsOnRoad
    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
    Rahman Rezaee over 3 years
    I 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
    justin0060 about 3 years
    Did you find a solution for it? @RahmanRezaee
  • Vipin Krishna
    Vipin Krishna over 2 years
    Just inserting didn't work for me. Run/debug app required before taking build
  • Imran Zahoor
    Imran Zahoor over 2 years
    Important note: uses-permission comes directly under manifest but not inside application. 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
    CopsOnRoad over 2 years
    @ImranZahoor It's already put directly under the manifest tag in the answer.
  • Imran Zahoor
    Imran Zahoor over 2 years
    While 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
    mekdigital over 2 years
    <3 try checking the connectivity of the device
  • Marwin Lebensky
    Marwin Lebensky about 2 years
    I know it's not that relevant, but your closing tag says maniFAST instead of manifest. Gotta go FAST!
  • CopsOnRoad
    CopsOnRoad about 2 years
    @MarwinLebensky Haha, thanks for pointing that out, I updated the post.