-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Flavor-conditional asset bundling does not work when declared within a direct main path dependencies #155755
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
Comments
Hi @alestiago flutter:
assets:
- assets/common/
- path: assets/dev/
flavors:
- dev
- path: assets/prod/
flavors:
- prod
And similar assets declaration in the package. Can you try to see if it works? |
Hi @huycozy, thanks for chiming in. Your suggestion is invalid, it does not bundle the flavored assets when defined in a dependency package, see below details for additional information. Additional informationFor clarity, this was the new directory structure: my_app/
├─ assets/
│ ├─ my_app_logo.png
│ ├─ my_app_logo-dev.png
│ ├─ my_app_logo-prod.png
├─ packages/
│ ├─ my_assets/
│ │ ├─ assets/
│ │ │ ├─ my_assets_logo.png
│ │ │ ├─ dev/
│ │ │ │ ├─ my_assets_logo-dev.png
│ │ │ ├─ prod/
│ │ │ │ ├─ my_assets_logo-prod.png This was the new pubspec within the # file: my_app/packages/my_assets/pubspec.yaml
flutter:
assets:
- assets/my_assets_logo.png
- path: assets/dev/
flavors:
- dev
- path: assets/prod/
flavors:
- prod And this was the examined APK after being built with: flutter build apk --flavor dev ![]() NOTE: Regardless if it can only accept directories in dependencies or not (which also failed) what has been described in the issue is clearly showing inconsistent behavior in pubspecs when using flavor-conditional bundling. The same syntax was used for the main application package and the direct main dependency package, and the conditional bundling only worked as expected for the main application package. |
Thanks for your response. I can also see the issue with my assets structure. When building apk with flavor, conditionally bundling does not work on package. My assets structure.
├── assets
│ ├── common
│ │ └── flutter.jpeg
│ ├── dev
│ │ └── flutter-dev.jpeg
│ └── prod
│ └── flutter-prod.jpeg
├── packages
│ └── my_assets
│ ├── assets
│ │ ├── common
│ │ │ └── flutter.jpeg
│ │ ├── dev
│ │ │ └── flutter-dev.jpeg
│ │ └── prod
│ │ └── flutter-prod.jpeg Output APK analysisThe complete sample project: flutter-flavor-conditionally-bundling-assets. Reproduced on Flutter master |
FYI @andrewkolos |
I would like to point out that this issue is not specific only to Android, as it also arises on iOS, according to #155404. |
Thank @feduke-nukem. Taking off Android label as this concerns a tool issue in general. |
Fixes #155755 When building the asset bundle during, the `--flavor` option isn't considered when searching for assets from dependencies. This PR fixes that. It's possible that when initially implementing this feature, I thought that flavor-conditional assets didn't make sense for packages. While I still think that way regarding pub packages, using this feature makes a lot more sense for monorepo projects. <details> <summary> Pre-launch checklist </summary> </details>
…156687) Fixes flutter#155755 When building the asset bundle during, the `--flavor` option isn't considered when searching for assets from dependencies. This PR fixes that. It's possible that when initially implementing this feature, I thought that flavor-conditional assets didn't make sense for packages. While I still think that way regarding pub packages, using this feature makes a lot more sense for monorepo projects. <details> <summary> Pre-launch checklist </summary> </details>
This fix should be available in the next Flutter release (3.27 as far as I'm aware), starting with the beta branch. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Uh oh!
There was an error while loading. Please reload this page.
Description
Flutter 3.22 introduced “Flavor-conditional asset bundling”, read more about them in the “Conditionally bundling assets based on flavor” documentation.
When declaring assets outside of the main application package and defining flavors for them the main application bundle does not account for these assets as expected.
Steps to reproduce
flutter pub add 'my_assets:{"path":"my_app/packages/my_assets"}' --directory my_app
The built APK is expected to be at: my_app/build/app/outputs/flutter-apk/app-dev-release.apk
Expected results
my_assets_logo-dev.png should have also been bundled in the APK but it was not.
Actual results
The following assets were included in the APK:
Code sample
Not applicable, see reproductive steps instead.
Screenshots or Video
Actual APK Analyzer results
Logs
Not applicable.
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: