Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] launch_icon with flavors not working #385

Open
nombrekeff opened this issue Jul 25, 2022 · 31 comments
Open

[BUG] launch_icon with flavors not working #385

nombrekeff opened this issue Jul 25, 2022 · 31 comments

Comments

@nombrekeff
Copy link

ℹ️ Info

Version: 0.9.3
Flutter version: 3.0.2

💬 Description

We have been using this package for a while, it worked perfectly until a couple of weeks ago. I've checked everything and it all seems correct. The issue is that when installing the app it always show the default launcher_icon instead of the one defined in flutter_launcher_icons-<flavor>.yaml

I've got 3 flavours, pre, prod and sandbox. But if I run flutter run --flavor sandbox, the app shows the default icon. Not the one defined in that flavor configuration file.

I've run flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-sandbox.yaml but it does not solve anything. Any idea what could be going on?

I had it set up with adaptive icons, but for testing, I tried with image_path instead.

📜 Pubspec.yaml

name: rec
description: Rec Barcelona app.
publish_to: 'none'
version: 2.3.0+81

environment:
  sdk: '>=2.12.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  flutter_secure_storage: ^5.0.2
  flutter_spinkit: ^5.1.0 
  flutter_easyloading: ^3.0.5
  flutter_speed_dial: ^4.6.6
  flutter_svg: ^0.23.0+1
  rec_api_dart: ^1.4.0-alpha.5
  # rec_api_dart: 
  #   path: /Users/keff_work/Documents/dev/work/REC/rec_api_dart
  contacts_service: ^0.6.3
  country_code_picker: ^2.0.2
  cupertino_icons: ^1.0.4
  dio: ^4.0.4
  geocoding: ^2.0.1
  google_maps_flutter: ^2.1.6
  qr_flutter: ^4.0.0
  mobile_scanner: ^2.0.0
  http: ^0.13.4
  http_interceptor: ^1.0.2
  intl: ^0.17.0
  package_info: ^2.0.2
  permission_handler: ^8.3.0
  provider: ^6.0.1
  sentry_flutter: ^6.5.1
  share: ^2.0.4
  shared_preferences: ^2.0.9
  timeago: ^3.1.0
  url_launcher: ^6.1.2
  webview_flutter: ^2.3.1
  image_picker: ^0.8.4+4 
  path: ^1.8.0
  path_provider: ^2.0.9
  pinput: ^2.2.9
  location: ^4.4.0
  collection: ^1.15.0-nullsafety.4
  flutter_dotenv: ^5.0.2
  modal_bottom_sheet: ^2.0.1
  styled_text: ^5.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  test: ^1.17.10 
  lints: ^1.0.1
  flutter_launcher_icons: ^0.9.3
  faker: ^2.0.0
  mockito: ^5.0.16
  dart_code_metrics: ^4.15.2

flutter:
  assets:
    - assets/
    - assets/adaptive_app_icon/
    - assets/custom-icons/
    - assets/markers/
    - assets/banners/
    - assets/cards/
    - i18n/ca.json
    - i18n/en.json
    - i18n/es.json
    - env/.env
  uses-material-design: true

Flavor file example

flutter_launcher_icons-pre.yaml

flutter_icons:    
  android: "launcher_icon"
  ios: true    
  image_path: "assets/adaptive_app_icon/pre.png"
  remove_alpha_ios: true

build.gradle

android {
flavorDimensions "default"
    productFlavors {
        sandbox {
            dimension "default"
            applicationId "com.barcelona.sandbox"
            versionNameSuffix "-sandbox"
            manifestPlaceholders = [appName: "[SANDBOX] RecBarcelona"]
        }

        pre {
            dimension "default"
            applicationId "com.barcelona.prec"
            versionNameSuffix "-pre"
            manifestPlaceholders = [appName: "[INT] RecBarcelona"]
        }

        prod {
            dimension "default"
            applicationId "com.barcelona.rec"
            manifestPlaceholders = [appName: "[INT] RecBarcelona"]
        }
    }
}
@nombrekeff
Copy link
Author

PD: I can share and add more info if needed, did not know exactly what info to add

@RatakondalaArun
Copy link
Contributor

Can you please try with these changes in flutter_launcher_icons-pre.yaml

flutter_icons:    
  android: true # should be bool or path to icon
  ios: true    
  image_path: "assets/adaptive_app_icon/pre.png" # path icon
  remove_alpha_ios: true

@nombrekeff
Copy link
Author

Yup, I've tried with no luck I'm afraid...

@nombrekeff
Copy link
Author

A couple of questions:
The icons are supposed to show up even when running in debug right? When running flutter run --flavor pre it should set up the correct icon, right?

After changing or adding new icons, I ran flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-sandbox.yaml. Am I supposed to run anything else so the changes take effect? I guess not as it was not mentioned in the docs, but just in case...

@RatakondalaArun
Copy link
Contributor

Can you provide me with these details

  • the platform on which this is happening (android, IOS, all)
  • Did you recently update the flutter tool?

if it is android try with this

# only generates icons for android platform
flutter_icons:    
  android: true # should be bool or path to icon
  ios: false 
  image_path_android: "assets/adaptive_app_icon/pre.png" #<- image path for android

@nombrekeff
Copy link
Author

nombrekeff commented Jul 26, 2022

It seems it's happening on all platforms. I've checked and the icons are generated correctly inside android/app/src and on ios/Runner/Assets.xcassets too. But they seem not to be applied when building or running (I don't know if that can give you any hint as to what's happening)

I did update flutter, a month or two back, from 2.7.3 to 3.0.2.

The above config should go in the pubspec.yml or inside flutter_launcher_icons-pre.yaml? I've tried adding it to flutter_launcher_icons-pre.yaml and when running flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-pre.yaml it prints:

✗ ERROR: InvalidConfigException 
Missing "image_path" or "image_path_android" + "image_path_ios" within configuration
pub finished with exit code 2

@RatakondalaArun
Copy link
Contributor

It seems it's happening on all platforms. I've checked and the icons are generated correctly inside android/app/src and on ios/Runner/Assets.xcassets too. But they seem not to be applied when building or running (I don't know if that can give you any hint as to what's happening)

Maybe there is a problem with the build cache

try running

flutter clean &&
flutter pub get &&
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-pre.yaml

@nombrekeff
Copy link
Author

Okay, I will try that. I think I tried it as well, but maybe not!! I'll let you know!

@nombrekeff
Copy link
Author

nombrekeff commented Jul 27, 2022

flutter clean &&
flutter pub get &&
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-pre.yaml

When running the above commands it gives me the same error as above, with the config you suggested.

this is the complete output:

Cleaning Xcode workspace...                                         6,7s
Deleting build...                                                  697ms
Deleting .dart_tool...                                              24ms
Deleting .packages...                                                0ms
Deleting Generated.xcconfig...                                       0ms
Deleting flutter_export_environment.sh...                            0ms
Deleting Flutter.podspec...                                          0ms
Deleting .flutter-plugins-dependencies...                            0ms
Deleting .flutter-plugins...                                         0ms
Running "flutter pub get" in app_with_lib...                     2.157ms
  ════════════════════════════════════════════
     FLUTTER LAUNCHER ICONS (v0.9.3)                               
  ════════════════════════════════════════════
  

Flavor: prod
• Creating default icons Android
• Adding a new Android launcher icon
• Building iOS launcher icon for prod

Flavor: sandbox
• Creating default icons Android
• Adding a new Android launcher icon
• Building iOS launcher icon for sandbox

Flavor: pre

✕ Could not generate launcher icons for flavors

✗ ERROR: InvalidConfigException 
Missing "image_path" or "image_path_android" + "image_path_ios" within configuration
pub finished with exit code 2

@RatakondalaArun
Copy link
Contributor

Can you try with this?

flutter_launcher_icons-pre.yaml

flutter_icons:    
  android: true # should be bool or path to icon
  ios: true    
  image_path: "assets/adaptive_app_icon/pre.png" # path icon
  remove_alpha_ios: true
flutter clean &&
flutter pub get &&
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-pre.yaml

@nombrekeff
Copy link
Author

Hey, I just tried this as well with no luck. It's still showing the incorrect icon... This weekend I will create a project from 0 and try to replicate this behaviour there and share it with you guys. I've tried a lot of things and the project is quite big, so there might be something wrong somewhere I can't find.

@nombrekeff
Copy link
Author

Hey there, I was just doing some tests and tried adding a new flavor. This new flavor works as expected, but the old ones still don't... I've deduced that for some reason, the old flavors use the launcher_icon located in android/app/src/main/res instead of the ic_launcher in android/app/src/<flavor>/res, any idea why this could be happening for some flavors but not others???

@nombrekeff
Copy link
Author

Ok, I've detected something weird. It seems this only happens on devices that installed the app prior to changing icons. If I try with new devices the icons are shown correctly, with old devices it always shows the first icon it had, even after removing the app and clearing the cache. How does this make sense? Do you know if android caches this in some way?

@RatakondalaArun
Copy link
Contributor

RatakondalaArun commented Aug 9, 2022

Do you know if android caches this in some way?

Maybe it depends on the android skin. Each skin has there own optimizations.

Try restarting your device, it should work most of the time

@nombrekeff
Copy link
Author

I tried but there's no luck. Oh well, I will blame it on android. As it's happened to more than one type of skin. I will keep investigating and if I find the reason I will make sure to update you.

@RatakondalaArun
Copy link
Contributor

Try testing them on the android emulator

@Reitenator
Copy link

I've also run in to this issue.

I can see that the icons are generated and placed in the correct folders.

I have a suspicion that it might not being built correctly when building the app with the --flavor flag.

It falls back to the default app-icon instead of the flavor-app-icon.

To solve it on Mac (xcode) it is required to change it direclty in xcode every time you need to change flavor.

Is there some trick to force xcode/android-studio to take the flavor-app-icons (like e.g. add an additional build-flag or something) ?

@kvenn
Copy link

kvenn commented Dec 10, 2022

I had to manually go into Targets Runner -> Build Settings -> Search for "Primary App Icon Set" and then put in the name of the asset as specified in the asset catalog for each type

The flavorizr library supports it correctly on iOS (but doesn't handle dynamic icons on Android...). Might be able to take inspiration from them on how they update the flavors in the ios icon processors.

@Reitenator
Copy link

I had to manually go into Targets Runner -> Build Settings -> Search for "Primary App Icon Set" and then put in the name of the asset as specified in the asset catalog for each type

Nice find! Works like a charm :)

@Letalus
Copy link

Letalus commented Jan 2, 2023

hey, I had the same issue like @nombrekeff. I fixed it quite easily but simply just removing the ic_launcher_foreground.xml file from the android/app/src/main/res/drawable folder. Somehow this always overwrote the other generated foreground files within the different flavors

@gonzasosa
Copy link

@nombrekeff I was facing the same issue and after deleting all the mipmap folders inside android/app/src/main/res it got fixed. If you have such folders in that location, try to remove them and then run the app again.

@abdu292
Copy link

abdu292 commented Feb 13, 2023

In case if it helps. Renaming this particular file solved the issue for me. This looks to be similar to what @gonzasosa did.
It appears that android was looking to the main/ folder.
image

cc @RatakondalaArun

Thanks!

@EArminjon
Copy link

EArminjon commented Feb 25, 2023

Same issue

flutter pub run flutter_launcher_icons:main -f .\splash_and_launch_assets\clienta\flutter_launcher_icons-clienta.yaml

Assets are created inside

 android/app/src/main/res/
 ios/Runner/Assets.xcassets/AppIcon.appiconset/

I've deleted main/res but same issue.
Flavor didn't work when config file is inside a sub folder.

flutter_launcher_icons: 0.12.0
flutter 3.3.4

@erickfrancis
Copy link

For me it worked, the solution was to add settings in root of the project.

image

@nguyen703
Copy link

I had to manually go into Targets Runner -> Build Settings -> Search for "Primary App Icon Set" and then put in the name of the asset as specified in the asset catalog for each type

The flavorizr library supports it correctly on iOS (but doesn't handle dynamic icons on Android...). Might be able to take inspiration from them on how they update the flavors in the ios icon processors.

It worked! Just because the asset is set $(ASSET_PREFIX)AppIcon by default. I had to changed it into AppIcon-$(ASSET_PREFIX), which is the correct one in Assets.xcassets. Thanks a lot! 😁

@MarkOSullivan94
Copy link
Collaborator

@nombrekeff by any chance did you use very_good_cli to create your app with the flavors? I'm aware there is an issue with flutter_launcher_icons not being able to update the icon for those projects: #466

@nombrekeff
Copy link
Author

@nombrekeff by any chance did you use very_good_cli to create your app with the flavors? I'm aware there is an issue with flutter_launcher_icons not being able to update the icon for those projects: #466

Hey @MarkOSullivan94, I'm afraid I did not. I created the project using the Flutter starter package as specified in their docs.

@MarkOSullivan94
Copy link
Collaborator

MarkOSullivan94 commented Apr 19, 2023

I've spent some time looking into why this is occurring for the Android app at least. It looks like the issue is to do with ic_launcher.xml within the mipmap-anydpi-v26 for both main and whatever flavor you're trying to run.

I setup a basic quick test with flutter_launcher_icons and found that if I delete both of these then ic_launcher.png which is generated by flutter_launcher_icons is used instead

@nombrekeff does this help you?

If not, might be good to try and create an open source project with a similar setup so I can help identify the issue

@mohmdramadn
Copy link

In case if it helps. Renaming this particular file solved the issue for me. This looks to be similar to what @gonzasosa did. It appears that android was looking to the main/ folder. image

cc @RatakondalaArun

Thanks!

This worked for me but I renamed the flavor file and it reloaded the flavor icon correctly

@TijnvandenEijnde
Copy link

So for me, none of the above solutions solved the problem.

Setup

In my project, I have 2 flavors:

  1. production
  2. development

For some reason when running the command: dart run flutter_launcher_icons -f flutter_launcher_icons*. It will generate the files for the production environment correctly, but not for my development flavor.

Problem

In the production/res folder, I have the following subfolders and files:

image

In the development/res folder, I have the same subfolders, however, the .png files are named differently, and I am not sure why:

image

If we take a look at my androidManifest.xml file you will see that android:icon is referring to @mipmap/launcher_icon.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.your_project">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon" <!-- RIGHT HERE -->
        android:label="Your Project">
        <activity ...>
        <meta-data ...>
        <meta-data ...>
        <meta-data ...>
    </application>
</manifest>

Solution

So the solution is to rename every file from ic_launcher to launcher_icon.

Be aware that it is not just .png files, I had to do the same for the .xml files, to make the adaptive icons work. Also whenever you run the command again to generate the files, keep in mind that you have to make manual changes.

I hope this is helpful.

@inamhwebelight
Copy link

In case if it helps. Renaming this particular file solved the issue for me. This looks to be similar to what @gonzasosa did. It appears that android was looking to the main/ folder. image

cc @RatakondalaArun

Thanks!

This works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests