I can't display images in my apk release in flutter
Subdirectories within a directory are not automatically included. You need to include every directory in your pubspec.yaml. Not sure how things worked on the emulator without this. So you would have (according to your asset structure):
assets:
- assets/images/Antiguo
- asests/images/Aparicion
...
Since the assets are within the assets/
folder, you also need to include that in your path:
Image.asset('assets/images/Kratos/kr1.jpg', ...);
Do a flutter clean
and try building again.
Brilosan8
Updated on January 05, 2023Comments
-
Brilosan8 over 1 year
I have created an app in flutter and when I test it on my mobile it does not show any image. Everything is fine, except the images.
I attach a picture of the pubspec.yaml, as I have the structure of assets and the cmd of how I create the apk. Each name in the images is a folder in which there are images inside.
I clarify that in Visual Studio Code that is where I have done it, in its emulator if the images are shown, but when I install the apk, no.
It is curious that if I add - assets/images/Atreus/ , when creating the apk, this weighs more (as it weighs more for that folder I added), but still not shown.
Thanks.
ADD: I have already fixed the red warning. It creates the apk without those warnings (I updated jdk to 15 and gradle to version 7.0.2), but the images are still not visible.
Code image:
Image.asset( 'images/Kratos/kr2.jpg', width: 100, height: 100, fit: BoxFit.cover, ),
Code image updated:
Code image: Image.asset( 'assets/images/Kratos/kr2.jpg', width: 100, height: 100, fit: BoxFit.cover, ),
NEW: Now I get this error. I have version 1.5 on my computer but I don't know how to select it.
Now, when I change the version manually in build.gradle ext.kotlin_version = '1.5' I get this error, and even if I do flutter clean again it doesn't fix the problem.
Ok. Beginner's mistake. I put the version '1.5' but I should have put '1.5.0' ... Similarly, the apk is created without fail but the images are not displayed.
NEWS: Images are already shown! Many thanks to user2233706. I can't give points for being a "newbie" but I appreciate it very much.
-
user2233706 almost 2 yearsYou should put formatted code in your question, not images of it.
-
Brilosan8 almost 2 yearsI have added one thing
-
user2233706 almost 2 yearsI've had issues where building twice mysteriously fixes the issue. But you can set the kotlin version in
android/build.gradle
and update this lineext.kotlin_version = 1.5
. -
Brilosan8 almost 2 yearsI have added what happens now
-
user2233706 almost 2 yearsCan you try debugging on the device? Maybe you'll see some errors in the debug console. From VSCode you can choose your device from the lower right, assuming you have USB debugging enabled. You also need to post a minimal example that reproduces the problem.
-
-
Brilosan8 almost 2 yearsI have done flutter clean and flutter pub get and the images still do not appear in the apk. Please help.
-
Brilosan8 almost 2 yearsI have already put the image of the code I use for the image.