Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.43k stars 653 forks source link

Does not work in APK #497

Open VincentBayliss opened 3 years ago

VincentBayliss commented 3 years ago

🐛 Bug Report

Works great when running in the IDE on either an emulator or a physical device via USB but once APK has been built and distributed to any device via Firebase App Distribution, no images appear.

I have allowed INTERNET permissions in the manifest file so that is not the issue. Using a normal Network Image widget or a FadeInImage.assetNetwork widget works fine but this package does not work when deployed out via App Distribution.

Permissions added to the AndroidManifest.xml files:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Expected behavior

To see images.

Reproduction steps

Get the CachedNetworkImage widget/package working as expected (so that you see the expected images and placeholders) then build out the APK and distribute via Firebase App Distribution and any Android device.

Configuration

Version: cached_network_image: ^2.2.0+1 Android Studio 4.1 classpath 'com.android.tools.build:gradle:4.1.0'

Platform:

  • Android (on Samsung and HTC phones)
renefloor commented 3 years ago

That's really strange. I've never heard of that. If you just build an APK and install it directly (without the firebase app distribution), does it give the same issues?

caobo171 commented 3 years ago

Yeah I'm facing exactly this issue too

VincentBayliss commented 3 years ago

Hi renefloor, just installed it directly and had the same issue. I have a circularAvatart with a profile picture (fed from Firestore) that works great with this package until its built into an APK and installed. I'm not saying its definitely this package thats the problem but it works fabulously in an emulator or on a hard-wired device. Its just when its bundled into an APK that the behaviour (or lack of) changes. I also suspect that there may be something a little more sinister going on here. The circularAvatar is on a card widget, along with a text-widget URL (using the url_launcher package). This does not launch either when the APK is build and installed but works great in the IDE with an emulator or hard-wired physical device. Either way, it would be nice to get to the bottom of what is going on.

Cheers, Vincent.

Eduardocoutto commented 3 years ago

I'm having the same problem

VincentBayliss commented 3 years ago

I've had some luck here but I don't know why. I'll reproduce what I did last night over the weekend and see if I can figure out what steps make this work and what steps don't. I have built a "release" APK and installed it and it's working great. Just need to figure out what triggers the error and what doesn't during the build process. I will let you guys know as soon as I have figured it out.

caobo171 commented 3 years ago

I resolved this problem by disable minify and shrink when building APK Add these lines on your app level build.gradle

buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so flutter run --release works. signingConfig signingConfigs.release shrinkResources false minifyEnabled false } }

VincentBayliss commented 3 years ago

Same deal, I found that if I did a "flutter run --release" and deployed the apk from that, it worked fine and the apk size was halved. The app was also optimised beyond belief and ran really fast and efficiently. Having said that though, I believe doing it that way is not advisable as it restricts compatibility. I found this was the case as I have an older test device that would not install the app when it was run this way. It would however install and run the fat version. What I did read was to do split apks to combat the compatibility problem. That is also the recommended method for distribution. I have not tested this yet but I certainly will test and report back.

renefloor commented 3 years ago

Are you able to get some crash logs related to this?

preetshah21699 commented 3 years ago

The same issue is in my case. The problem is that it doesn't give any errors. It just doesn't load the image and keeps on showing the placeholder widget. I've tried to figure it out but I'm unable to.

renefloor commented 3 years ago

Looks like it is indeed an issue with how minify/proguard handles the sqflite plugin: https://github.com/tekartik/sqflite/issues/452#issuecomment-655602329

Setting shrinkResources and minifyEnabled to false is the easiest solution for now.

Boehrsi commented 3 years ago

Just added a comment to the mentioned Sqflite issue which provides a quite simple workaround to get everything working with shrinking enabled => https://github.com/tekartik/sqflite/issues/452#issuecomment-731835148

royryando commented 3 years ago

I resolved this problem by disable minify and shrink when building APK Add these lines on your app level build.gradle

buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so flutter run --release works. signingConfig signingConfigs.release shrinkResources false minifyEnabled false } }

Thanks @caobo171 it works!

amigax commented 2 years ago

Problem still persists here even with that, any other ideas?