Search code examples
androidflutterimage-loading

Flutter CachedNetworkImage doesn't work for App downloaded from playstore, stuck on placeholder


I'm using CachedNetworkImage in my app and it works fine when I run it in debug or release on Android, however when I upload the aab to the Play Store and download the app from the Play Store, the image is just stuck on the placeholder.

Here's how I'm using it in the app. Note that I use a Text widget for the placeholder and the error so that I can visually debug any issues on the release version:

child: Stack(
          children: <Widget>[
            url != null
                ? CachedNetworkImage(
              imageUrl: url,
              errorWidget: (context, url, error) => Text("$error"),
              placeholder: (context, url) => Text("Loading $url"),
              imageBuilder: (context, imageProvider) => Container(
                width: double.infinity,
                height: 150,
                decoration: BoxDecoration(
                  image: DecorationImage(image: imageProvider, fit: BoxFit.fitWidth),
                ),
              ),
            )
                : Container(),

It just stays on the placeholder and looks like this It just stays on the placeholder and looks like this

I'm using the latest version of cached_network_image in the pubspec:

cached_network_image: ^2.4.1

Here's what I've tried so far to help narrow down the problem:

  1. Using Image.network(url) instead of CachedNetworkImage. The images load fine when I do this, so I know it's not a problem with the internet or the url.
  2. Running a release build on the device using flutter run --release. This works fine, the images load correctly.
  3. Trying out multiple devices. I tried using a Samsung Galaxy 8 on Android 8 and a Pixel 2xl on Android 11. Both work fine with debug builds and release builds, but not when downloaded from the Play Store.
  4. Making sure the URL is publicly accessible and that internet permissions are enabled. The app is able to load other content from the internet fine and the image url is on a public domain.

Solution

  • I ended up finding the solution in the github issues here github.com/Baseflow/flutter_cached_network_image/issues/497. Turns out it is a proguard issue with the sqflite library that CachedNetworkImage uses. The solution, until they fix it in the library, is to add a the default proguard file to the build.gradle file:

    buildTypes {
            release {
                signingConfig signingConfigs.release
                minifyEnabled true // Add these lines
                shrinkResources true // Add these lines
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt') // Add these lines
            }
        }
    

    I'm actually really surprised no one else has posted about this on SO that I could find, seems like a major breaking change to the library.