)]}'
{
  "commit": "016eb85177c9cef03f62c2ec2ad797398952e310",
  "tree": "6ec0cf3e9c90d4d23a95ebeac4c8e4d57f9beb57",
  "parents": [
    "0dfb2c1311117efd89a70e68268dd5b31837ab31"
  ],
  "author": {
    "name": "Andrew Kolos",
    "email": "andrewrkolos@gmail.com",
    "time": "Thu Dec 07 15:50:00 2023 -0800"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Thu Dec 07 23:50:00 2023 +0000"
  },
  "message": "Support conditional bundling of assets based on `--flavor` (#132985)\n\nProvides support for conditional bundling of assets through the existing `--flavor` option for `flutter build` and `flutter run`. Closes https://github.com/flutter/flutter/issues/21682. Resolves https://github.com/flutter/flutter/issues/136092\r\n\r\n## Change\r\nWithin the `assets` section pubspec.yaml, the user can now specify one or more `flavors` that an asset belongs to. Consider this example:\r\n\r\n```yaml\r\n# pubspec.yaml\r\nflutter:\r\n  assets:\r\n    - assets/normal-asset.png\r\n    - path: assets/vanilla/ice-cream.png\r\n      flavors: \r\n        - vanilla\r\n    - path: assets/strawberry/ice-cream.png\r\n      flavors:\r\n        - strawberry\r\n```\r\n\r\nWith this pubspec,\r\n* `flutter run --flavor vanilla` will not include `assets/strawberry/ice-cream.png` in the build output.\r\n* `flutter run --flavor strawberry` will not include `assets/vanilla/ice-cream.png`.\r\n* `flutter run` will only include `assets/normal-asset.png`.\r\n\r\n## Open questions\r\n\r\n* Should this be supported for all platforms, or should this change be limited to ones with documented `--flavor` support (Android, iOS, and (implicitly) MacOS)? This PR currently only enables this feature for officially supported platforms.\r\n\r\n## Design thoughts, what this PR does not do, etc.\r\n\r\n### This does not provide an automatic mapping/resolution of asset keys/paths to others based on flavor at runtime.\r\n\r\nThe implementation in this PR represents a simplest approach. Notably, it does not give Flutter the ability to dynamically choose an asset based on flavor using a single asset key. For example, one can\u0027t use `Image.asset(\u0027config.json\u0027)` to dynamically choose between different \"flavors\" of `config.json` (such as `dev-flavor/config.json` or `prod-flavor/config.json`). However, a user could always implement such a mechanism in their project or in a library by examining the flavor at runtime.\r\n\r\n### When multiple entries affect the same file and 1) at least one of these entries have a `flavors` list provided and 2) these lists are not equivalent, we always consider the manifest to be ambiguous and will throw a `ToolExit`. \r\n\r\n\u003cdetails\u003e\r\nFor example, these manifests would all be considered ambiguous:\r\n\r\n```yaml\r\nassets:\r\n  - assets/\r\n  - path: assets/vanilla.png\r\n    flavors: \r\n      - vanilla\r\n\r\nassets:\r\n  - path: assets/vanilla/\r\n    flavors: \r\n      - vanilla\r\n  - path: assets/vanilla/cherry.png\r\n     flavor:\r\n      - cherry\r\n\r\n# Thinking towards the future where we might add glob/regex support and more conditions other than flavor:\r\nassets:\r\n  - path: assets/vanilla/**\r\n    flavors:\r\n      - vanilla\r\n  - path: assets/**/ios/**\r\n    platforms: \r\n       - ios\r\n\r\n# Ambiguous in the case of assets like \"assets/vanilla/ios/icon.svg\" since we \r\n# don\u0027t know if flavor `vanilla` and platform `ios` should be combined using or-logic or and-logic.\r\n```\r\n\r\nSee [this review comment thread](https://github.com/flutter/flutter/pull/132985#discussion_r1381909942) for the full story on how I arrived at this decision.\r\n\u003c/details\u003e\r\n\r\n### This does not support Android\u0027s multidimensional flavors feature (in an intuitive way)\r\n\r\n\u003cdetails\u003e\r\n\r\nConder this excerpt from a Flutter project\u0027s android/app/build.gradle file:\r\n\r\n```groovy\r\nandroid {\r\n    // ...\r\n\r\n    flavorDimensions \"mode\", \"api\"\r\n\r\n    productFlavors {\r\n        free {\r\n            dimension \"mode\"\r\n            applicationIdSuffix \".free\"\r\n        }\r\n\r\n        premium {\r\n            dimension \"mode\"\r\n            applicationIdSuffix \".premium\"\r\n        }\r\n\r\n        minApi23 {\r\n            dimension \"api\"\r\n            versionNameSuffix \"-minApi23\"\r\n        }\r\n\r\n        minApi21 {\r\n            dimension \"api\"\r\n            versionNameSuffix \"-minApi21\"\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nIn this setup, the following values are valid `--flavor` are valid `freeMinApi21`, `freeMinApi23`, `premiumMinApi21`, and `premiumMinApi23`. We call these values \"flavor combinations\". Consider the following from the Android documentation[^1]:\r\n\r\n\u003e In addition to the source set directories you can create for each individual product flavor and build variant, you can also create source set directories for each combination of product flavors. For example, you can create and add Java sources to the src/demoMinApi24/java/ directory, and Gradle uses those sources only when building a variant that combines those two product flavors.\r\n\u003e \r\n\u003e Source sets you create for product flavor combinations have a higher priority than source sets that belong to each individual product flavor. To learn more about source sets and how Gradle merges resources, read the section about how to [create source sets](https://developer.android.com/build/build-variants#sourcesets).\r\n\r\nThis feature will not behave in this way. If a user utilizes this feature and also Android\u0027s multidimensional flavors feature, they will have to list out all flavor combinations that contain the flavor they want to limit an asset to:\r\n\r\n```yaml\r\nassets:\r\n  - assets/free/\r\n    flavors:\r\n      - freeMinApi21\r\n      - freeMinApi23\r\n```\r\n\r\nThis is mostly due to a technical limitation in the hot-reload feature of `flutter run`. During a hot reload, the tool will try to update the asset bundle on the device, but the tool does not know the flavors contained within the flavor combination (that the user passes to `--flavor`). Gradle is the source of truth of what flavors were involved in the build, and `flutter run` currently does not access to that information since it\u0027s an implementation detail of the build process. We could bubble up this information, but it would require a nontrivial amount of engineering work, and it\u0027s unclear how desired this functionality is. It might not be worth implementing.\r\n\r\n\u003c/details\u003e\r\n\r\nSee https://flutter.dev/go/flavor-specific-assets for the (outdated) design document. \r\n\r\n\u003csummary\u003ePre-launch Checklist\u003c/summary\u003e\r\n\r\n\u003c/details\u003e\r\n\r\n[^1]: https://developer.android.com/build/build-variants#flavor-dimensions",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "2be63de6062ff6a0da355943dacb4b7584837883",
      "old_mode": 33188,
      "old_path": "dev/bots/pubspec.yaml",
      "new_id": "b00966d5ff7dc7f3e8016df375d0b5bd4245bafd",
      "new_mode": 33188,
      "new_path": "dev/bots/pubspec.yaml"
    },
    {
      "type": "modify",
      "old_id": "2db0956f79a62500d5a3efff0c547532155581f1",
      "old_mode": 33188,
      "old_path": "dev/devicelab/bin/tasks/flavors_test.dart",
      "new_id": "e9ebe408248f4510066afad5f781f2c86c3ea637",
      "new_mode": 33188,
      "new_path": "dev/devicelab/bin/tasks/flavors_test.dart"
    },
    {
      "type": "modify",
      "old_id": "4e84ed4ec3566ef4bd00f4f97e7e692e924b3971",
      "old_mode": 33188,
      "old_path": "dev/devicelab/bin/tasks/flavors_test_ios.dart",
      "new_id": "120b2be41ff1f4f77686bb41f2d26e33f5a9523c",
      "new_mode": 33188,
      "new_path": "dev/devicelab/bin/tasks/flavors_test_ios.dart"
    },
    {
      "type": "modify",
      "old_id": "e938780138570e7d37971ec9e1f648bed03acd37",
      "old_mode": 33188,
      "old_path": "dev/devicelab/pubspec.yaml",
      "new_id": "ed834b7a61b45e161f4c43d43935c979ba51aed5",
      "new_mode": 33188,
      "new_path": "dev/devicelab/pubspec.yaml"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "b804e9886abc80a2bcc060f3371f8df5c2ffa16c",
      "new_mode": 33188,
      "new_path": "dev/integration_tests/flavors/assets/common/common.txt"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "8f7a269f728e65ee3f7817ae831eccb16c3c76fd",
      "new_mode": 33188,
      "new_path": "dev/integration_tests/flavors/assets/free/free.txt"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "c6b999fd68e8c99d168863169ef6e71cb1a0b850",
      "new_mode": 33188,
      "new_path": "dev/integration_tests/flavors/assets/paid/paid.txt"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "f79024521897f538ef76f662c34f19ed1c8ee6f3",
      "new_mode": 33188,
      "new_path": "dev/integration_tests/flavors/assets/premium/premium.txt"
    },
    {
      "type": "modify",
      "old_id": "6b05736c805b5084eb07ce42c7c8ba12d05d0970",
      "old_mode": 33188,
      "old_path": "dev/integration_tests/flavors/pubspec.yaml",
      "new_id": "d0c979db4eb52391958106bb809c7c0fb7a290a7",
      "new_mode": 33188,
      "new_path": "dev/integration_tests/flavors/pubspec.yaml"
    },
    {
      "type": "modify",
      "old_id": "70e856405e9e282b9c9c7e61391e9820c97d515e",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/bin/xcode_backend.dart",
      "new_id": "dca13dad5f74d834a9758a943b7db42c0f7329d6",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/bin/xcode_backend.dart"
    },
    {
      "type": "modify",
      "old_id": "d7580f7c9823320ec96c1852adab12b26b4c8479",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/gradle/src/main/groovy/flutter.groovy",
      "new_id": "2bbce95251f335482a2923b95db4af67d367648c",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/gradle/src/main/groovy/flutter.groovy"
    },
    {
      "type": "modify",
      "old_id": "7eda50bc1f7de1fb2c9f46276535588fc70a96af",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/asset.dart",
      "new_id": "9d936156d5f2b34a24a0d122f2821ffbe6a91722",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/asset.dart"
    },
    {
      "type": "modify",
      "old_id": "748b0086c21250076feaece4c4b95acb2a1c0d32",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/base/deferred_component.dart",
      "new_id": "6bf2219e9e75dce7ca96ce412f8907692a5f5ffd",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/base/deferred_component.dart"
    },
    {
      "type": "modify",
      "old_id": "825b0df74adbb528c664214b59a6f44874737c20",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/build_info.dart",
      "new_id": "b42edc1d51f5d454ffad77db1854c3e18b706b3c",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/build_info.dart"
    },
    {
      "type": "modify",
      "old_id": "1c8e8fb7855a620affba26c55641a9b47d620eee",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/build_system/targets/android.dart",
      "new_id": "8254234de27d988962341dd24eccea4a345fd6a9",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/build_system/targets/android.dart"
    },
    {
      "type": "modify",
      "old_id": "dc9c9aff910055ef77cb560153a1a2a1181fa4ec",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/build_system/targets/assets.dart",
      "new_id": "6ad00d1ebadc94daf84fdcbe6640a9c4a49aa88e",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/build_system/targets/assets.dart"
    },
    {
      "type": "modify",
      "old_id": "c3507abb349aad9f6b660f93dcec7b4f1d10d56c",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/build_system/targets/common.dart",
      "new_id": "461638298bad6e67b9681d7ef441cd492e9fc110",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/build_system/targets/common.dart"
    },
    {
      "type": "modify",
      "old_id": "66c806b60c3abc765250fa00279cfbcf0405c3c5",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/build_system/targets/ios.dart",
      "new_id": "9336cd741514b30a701b1287b6a4954ee6508ac0",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/build_system/targets/ios.dart"
    },
    {
      "type": "modify",
      "old_id": "85bd01a9e58b503c433b90b9668818f682865ae5",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/build_system/targets/macos.dart",
      "new_id": "7cd1e8193d747476be997cff17919e6604f5d712",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/build_system/targets/macos.dart"
    },
    {
      "type": "modify",
      "old_id": "f1ec2b13573c06029338b059ba09466089f339a9",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/bundle_builder.dart",
      "new_id": "496f2d0138e5c37ba1570b65c15edaf6f6aff006",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/bundle_builder.dart"
    },
    {
      "type": "modify",
      "old_id": "68554d6ce957296156e204027091fd19a0a70dec",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/flutter_manifest.dart",
      "new_id": "473413982b85f336c099b9a1b109b620e1b9467d",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/flutter_manifest.dart"
    },
    {
      "type": "modify",
      "old_id": "117e0f389c79cb0f0f27843e46682e05af2bec6e",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/lib/src/run_hot.dart",
      "new_id": "740b18961e75e2cbf6b351a876d6f5daab01bfe3",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/lib/src/run_hot.dart"
    },
    {
      "type": "modify",
      "old_id": "3032eafd9a0283634f58551bba20c8161c5cedc6",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/commands.shard/hermetic/run_test.dart",
      "new_id": "6aef5d2ebb4465e4b3c215ac2fbe239adae2aec5",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/commands.shard/hermetic/run_test.dart"
    },
    {
      "type": "modify",
      "old_id": "4b798f61ec6654a215388481f75439ee8d39aea4",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/asset_bundle_test.dart",
      "new_id": "3704f1bb08b983949c1b634b1343bd19c898d5d1",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/asset_bundle_test.dart"
    },
    {
      "type": "modify",
      "old_id": "3a718f40f29f90c56935568605066f42655fa0d8",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/base/deferred_component_test.dart",
      "new_id": "c2acb6829f1c1986d7875d5beb7595bce1dfb590",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/base/deferred_component_test.dart"
    },
    {
      "type": "modify",
      "old_id": "ae1c92529da01ebfbbb157e9126916f97112ade9",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/build_info_test.dart",
      "new_id": "0ef3c35945a09d5008139cc03ebfb4681a057590",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/build_info_test.dart"
    },
    {
      "type": "modify",
      "old_id": "e021361f0385ae814b1f90a50cc7bd43c12472fd",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart",
      "new_id": "0a06c7d603578a865bb40f9af5375acbbbd3e425",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart"
    },
    {
      "type": "modify",
      "old_id": "d4b4e5fcf1098386d9210c7fa719d9de3281d8c4",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/devfs_test.dart",
      "new_id": "4872cddaa6cfea42f0388fa25c4f3638d056a9e4",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/devfs_test.dart"
    },
    {
      "type": "modify",
      "old_id": "d0ca23fc3bf814593c244ecb6c4ba738b11a8197",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/flutter_manifest_test.dart",
      "new_id": "dc048f5c8fecd7d46e006dff9d501f506def4db5",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/flutter_manifest_test.dart"
    },
    {
      "type": "modify",
      "old_id": "521564443760766bebb74c9ad6c8be28d8b2f633",
      "old_mode": 33188,
      "old_path": "packages/flutter_tools/test/general.shard/xcode_backend_test.dart",
      "new_id": "b91968bd9fdfe7dfe1d222445f340a2084cda2ed",
      "new_mode": 33188,
      "new_path": "packages/flutter_tools/test/general.shard/xcode_backend_test.dart"
    }
  ]
}
