1. 14 Dec, 2023 1 commit
  2. 08 Dec, 2023 1 commit
    • auto-submit[bot]'s avatar
      Reverts "Support conditional bundling of assets based on `--flavor`" (#139787) · 21766a4f
      auto-submit[bot] authored
      Reverts flutter/flutter#132985
      Initiated by: christopherfujino
      This change reverts the following previous change:
      Original Description:
      Provides 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
      
      ## Change
      Within the `assets` section pubspec.yaml, the user can now specify one or more `flavors` that an asset belongs to. Consider this example:
      
      ```yaml
      # pubspec.yaml
      flutter:
        assets:
          - assets/normal-asset.png
          - path: assets/vanilla/ice-cream.png
            flavors: 
              - vanilla
          - path: assets/strawberry/ice-cream.png
            flavors:
              - strawberry
      ```
      
      With this pubspec,
      * `flutter run --flavor vanilla` will not include `assets/strawberry/ice-cream.png` in the build output.
      * `flutter run --flavor strawberry` will not include `assets/vanilla/ice-cream.png`.
      * `flutter run` will only include `assets/normal-asset.png`.
      
      ## Open questions
      
      * 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.
      
      ## Design thoughts, what this PR does not do, etc.
      
      ### This does not provide an automatic mapping/resolution of asset keys/paths to others based on flavor at runtime.
      
      The 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't use `Image.asset('config.json')` 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.
      
      ### 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`. 
      
      <details>
      For example, these manifests would all be considered ambiguous:
      
      ```yaml
      assets:
        - assets/
        - path: assets/vanilla.png
          flavors: 
            - vanilla
      
      assets:
        - path: assets/vanilla/
          flavors: 
            - vanilla
        - path: assets/vanilla/cherry.png
           flavor:
            - cherry
      
      # Thinking towards the future where we might add glob/regex support and more conditions other than flavor:
      assets:
        - path: assets/vanilla/**
          flavors:
            - vanilla
        - path: assets/**/ios/**
          platforms: 
             - ios
      
      # Ambiguous in the case of assets like "assets/vanilla/ios/icon.svg" since we 
      # don't know if flavor `vanilla` and platform `ios` should be combined using or-logic or and-logic.
      ```
      
      See [this review comment thread](https://github.com/flutter/flutter/pull/132985#discussion_r1381909942) for the full story on how I arrived at this decision.
      </details>
      
      ### This does not support Android's multidimensional flavors feature (in an intuitive way)
      
      <details>
      
      Conder this excerpt from a Flutter project's android/app/build.gradle file:
      
      ```groovy
      android {
          // ...
      
          flavorDimensions "mode", "api"
      
          productFlavors {
              free {
                  dimension "mode"
                  applicationIdSuffix ".free"
              }
      
              premium {
                  dimension "mode"
                  applicationIdSuffix ".premium"
              }
      
              minApi23 {
                  dimension "api"
                  versionNameSuffix "-minApi23"
              }
      
              minApi21 {
                  dimension "api"
                  versionNameSuffix "-minApi21"
              }
          }
      }
      ```
      
      In 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]:
      
      > 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.
      > 
      > 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).
      
      This feature will not behave in this way. If a user utilizes this feature and also Android's multidimensional flavors feature, they will have to list out all flavor combinations that contain the flavor they want to limit an asset to:
      
      ```yaml
      assets:
        - assets/free/
          flavors:
            - freeMinApi21
            - freeMinApi23
      ```
      
      This 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's 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's unclear how desired this functionality is. It might not be worth implementing.
      
      </details>
      
      See https://flutter.dev/go/flavor-specific-assets for the (outdated) design document. 
      
      <summary>Pre-launch Checklist</summary>
      
      </details>
      
      [^1]: https://developer.android.com/build/build-variants#flavor-dimensions
      21766a4f
  3. 07 Dec, 2023 1 commit
    • Andrew Kolos's avatar
      Support conditional bundling of assets based on `--flavor` (#132985) · 016eb851
      Andrew Kolos authored
      Provides 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
      
      ## Change
      Within the `assets` section pubspec.yaml, the user can now specify one or more `flavors` that an asset belongs to. Consider this example:
      
      ```yaml
      # pubspec.yaml
      flutter:
        assets:
          - assets/normal-asset.png
          - path: assets/vanilla/ice-cream.png
            flavors: 
              - vanilla
          - path: assets/strawberry/ice-cream.png
            flavors:
              - strawberry
      ```
      
      With this pubspec,
      * `flutter run --flavor vanilla` will not include `assets/strawberry/ice-cream.png` in the build output.
      * `flutter run --flavor strawberry` will not include `assets/vanilla/ice-cream.png`.
      * `flutter run` will only include `assets/normal-asset.png`.
      
      ## Open questions
      
      * 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.
      
      ## Design thoughts, what this PR does not do, etc.
      
      ### This does not provide an automatic mapping/resolution of asset keys/paths to others based on flavor at runtime.
      
      The 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't use `Image.asset('config.json')` 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.
      
      ### 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`. 
      
      <details>
      For example, these manifests would all be considered ambiguous:
      
      ```yaml
      assets:
        - assets/
        - path: assets/vanilla.png
          flavors: 
            - vanilla
      
      assets:
        - path: assets/vanilla/
          flavors: 
            - vanilla
        - path: assets/vanilla/cherry.png
           flavor:
            - cherry
      
      # Thinking towards the future where we might add glob/regex support and more conditions other than flavor:
      assets:
        - path: assets/vanilla/**
          flavors:
            - vanilla
        - path: assets/**/ios/**
          platforms: 
             - ios
      
      # Ambiguous in the case of assets like "assets/vanilla/ios/icon.svg" since we 
      # don't know if flavor `vanilla` and platform `ios` should be combined using or-logic or and-logic.
      ```
      
      See [this review comment thread](https://github.com/flutter/flutter/pull/132985#discussion_r1381909942) for the full story on how I arrived at this decision.
      </details>
      
      ### This does not support Android's multidimensional flavors feature (in an intuitive way)
      
      <details>
      
      Conder this excerpt from a Flutter project's android/app/build.gradle file:
      
      ```groovy
      android {
          // ...
      
          flavorDimensions "mode", "api"
      
          productFlavors {
              free {
                  dimension "mode"
                  applicationIdSuffix ".free"
              }
      
              premium {
                  dimension "mode"
                  applicationIdSuffix ".premium"
              }
      
              minApi23 {
                  dimension "api"
                  versionNameSuffix "-minApi23"
              }
      
              minApi21 {
                  dimension "api"
                  versionNameSuffix "-minApi21"
              }
          }
      }
      ```
      
      In 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]:
      
      > 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.
      > 
      > 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).
      
      This feature will not behave in this way. If a user utilizes this feature and also Android's multidimensional flavors feature, they will have to list out all flavor combinations that contain the flavor they want to limit an asset to:
      
      ```yaml
      assets:
        - assets/free/
          flavors:
            - freeMinApi21
            - freeMinApi23
      ```
      
      This 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's 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's unclear how desired this functionality is. It might not be worth implementing.
      
      </details>
      
      See https://flutter.dev/go/flavor-specific-assets for the (outdated) design document. 
      
      <summary>Pre-launch Checklist</summary>
      
      </details>
      
      [^1]: https://developer.android.com/build/build-variants#flavor-dimensions
      016eb851
  4. 19 Oct, 2023 1 commit
  5. 21 Sep, 2023 1 commit
  6. 16 Aug, 2023 1 commit
  7. 15 Aug, 2023 1 commit
  8. 05 May, 2023 1 commit
  9. 14 Apr, 2023 1 commit
  10. 11 Nov, 2022 1 commit
  11. 26 Sep, 2022 1 commit
  12. 30 Aug, 2022 1 commit
  13. 27 Apr, 2022 1 commit
  14. 11 Apr, 2022 1 commit
  15. 10 Apr, 2022 1 commit
  16. 30 Mar, 2022 1 commit
  17. 22 Mar, 2022 1 commit
    • Chris Bracken's avatar
      [macOS] Use arm64 snapshot in arm64 App.framework (#100504) · fd3c34c9
      Chris Bracken authored
      Previously, https://github.com/flutter/flutter/pull/100271 enabled
      building universal macOS binaries by default, but included a bug causing
      the arm64 App.framework to be built such that the TEXT section
      containing the app instructions built by gen_snapshot incorrectly
      contained x86_64 instructions rather than arm64 instructions.
      
      When building macOS (and iOS) apps, Flutter builds them in three
      components:
      * The Runner application: built by Xcode
      * The bundled App.framework: built from assembly code generated by
        gen_snapshot from the application's Dart sources.
      * The bundled FlutterMacOS.framework: built as part of the engine build
        and packaged by copying the distributed binary framework from our
        artifacts cache.
      
      Building App.framework consists of the following steps:
      * For each architecture, invoke gen_snapshot to generate
        architecture-specific assembly code, which is then built to object
        code and linked into an architecture-specific App.framework.
      * Use the `lipo` tool to generate a universal binary that includes both
        x86_64 and arm64 architectures.
      
      Previously, we were building architecture specific App.framework
      binaries. However, for all architectures we were (mistakenly) invoking
      the general `gen_snapshot` tool (which emitted x64 instructions, and
      which is now deprecated) instead of the architecture-specific
      `gen_snapshot_x86` and `gen_snapshot_arm64` builds which emit
      instructions for the correct architecture.
      
      This change introduces a small refactoring, which is to split the
      `getNameForDarwinArch` function into two functions:
      * `getDartNameForDarwinArch`: the name for the specified architecture as
        used in the Dart SDK, for example as the suffix of `gen_snapshot`.
      * `getNameForDarwinArch`: the name for the specified architecture
        as used in Apple tools, for example as an argument to `lipo`. For
        consistency, and to match developer expectations on Darwin platforms,
        this is also the name used in Flutter's build outputs.
      
      Issue: https://github.com/flutter/flutter/issues/100348
      fd3c34c9
  18. 07 Sep, 2021 1 commit
  19. 20 May, 2021 1 commit
  20. 08 May, 2021 1 commit
  21. 08 Apr, 2021 1 commit
  22. 02 Feb, 2021 1 commit
    • Jonah Williams's avatar
      [flutter_tools] switch dart defines to base64 to avoid windows control characters (#75027) · 44d5950d
      Jonah Williams authored
      = gets escaped into %3D which seems to be tripping up cmake on windows since % is a control character. Switch to base64 encoding, since this does not have % nor , in the output character set.
      
      This change is not trivially cherry pickable, and isn't tested on windows aside from my local, manual tests due to the planned CI work not being complete yet.
      
      Fixes #75017
      Fixes #74705
      44d5950d
  23. 27 Jan, 2021 1 commit
  24. 25 Aug, 2020 1 commit
    • Jonah Williams's avatar
      [flutter_tools] support code size tooling on iOS, linux, windows, macOS, and... · 059de153
      Jonah Williams authored
      [flutter_tools] support code size tooling on iOS, linux, windows, macOS, and Android on Windows (#63610)
      
      Adds support for size analysis on iOS, macOS, linux, and Windows - using an uncompressed directory based approach. The output format is not currently specified.
      
      Adds support for size analysis on android on windows, switching to package:archive
      
      Updates the console format to display as a tree, allowing longer paths. Increases the number of dart libraries shown (to avoid only ever printing the flutter/dart:ui libraries, which dominate the size)
      059de153
  25. 25 Jun, 2020 1 commit
    • Jonah Williams's avatar
      [flutter_tools] remove most use of global packages path (#60231) · 82a6f9bf
      Jonah Williams authored
      The global packages path could cause tests to fail when it would be overriden to unexpected (in test setup) values. Remove most usage and make it a configuration on buildInfo, along with most other build information. Cleanup the asset builder to require the .packages path and the resident runners to no longer require it, since they already have the information in build_info.
      
      It needs to stick around for the fuchsia deps we do not control.
      
      Filled #60232 for remaining work.
      82a6f9bf
  26. 09 Jun, 2020 1 commit
  27. 04 Jun, 2020 1 commit
  28. 27 May, 2020 1 commit
  29. 05 May, 2020 1 commit
  30. 26 Apr, 2020 1 commit
    • Jonah Williams's avatar
      [flutter_tools] quality pass on Linux build (#55556) · dd88b204
      Jonah Williams authored
      - Update the Linux build to support most of the build configuration, though like windows most only make sense for profile/release.
      - Ensure VERBOSE_SCRIPT_LOGGING is set when the logger is verbose
      - Automatically run pub get like other build commands
      dd88b204
  31. 06 Mar, 2020 1 commit
  32. 04 Mar, 2020 2 commits
  33. 28 Feb, 2020 2 commits
  34. 27 Feb, 2020 2 commits
  35. 12 Feb, 2020 1 commit
  36. 06 Feb, 2020 1 commit
  37. 27 Jan, 2020 1 commit