Skip to content

--dart-define-from-file entries are available in the environment during Xcode build when they should not be #136444

Closed

Description

@fstotz

Is there an existing issue for this?

Steps to reproduce

  1. create a flutter project with IOS support
  2. change the "CFBundleDisplayName" in the Info.plist of the runner to use a new variable
  3. run the app and set the variable using --dart-define

If I use --dart-define-from-file instead it is working fine

Expected results

The app name is changed to the one set in the --dart-define variable

Actual results

The app name is falling back to Runner because the variable is not set

Code sample

Code sample

https://github.com/felixmede/dart_define_issue

[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.7, on macOS 13.6 22G120 darwin-x64, locale en)
    • Flutter version 3.13.7 on channel stable at
      /Users/fstotz/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2f708eb839 (3 days ago), 2023-10-09 09:58:08 -0500
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/fstotz/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/fstotz/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.83.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.29.0

[✓] Connected device (4 available)
    • iPhone_13_AI (mobile)       • 00008110-000978A81E52401E            • ios            • iOS 17.0.3 21A360
    • Iphone 6s IOS 14.5 (mobile) • BCF2B76E-B095-4562-A906-0ED50070D680 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • macOS (desktop)             • macos                                • darwin-x64     • macOS 13.6 22G120 darwin-x64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 117.0.5938.149

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. dam-ease commented on Oct 12, 2023

    @dam-ease

    Hi @felixmede. Thanks for filing this, I cloned your project, ran the app and set the variable using --dart-define and it works fine, same with --dart-define-from-file. Can you share the command you are running in your terminal and the result you are getting?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 12, 2023
  3. fstotz commented on Oct 13, 2023

    @fstotz
    Author

    If I am running flutter run lib/main.dart --dart-define=DEFINEEXAMPLE_APP_NAME=testname the app name is Runner
    If I am running flutter run lib/main.dart --dart-define-from-file=config.json the app name is awesomeApp1

    I think it started to happen after I upgraded to the newest version of Xcode

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 13, 2023
  5. dam-ease commented on Oct 13, 2023

    @dam-ease

    Thanks for your response @felixmede. I thought you were describing a crash earlier. I can see this on the latest master and stable channels. This doesn't seem peculiar to the newest Xcode version as I can reproduce the same behaviour with Xcode 14.3.1.

    stable, master flutter doctor -v

    [✓] Flutter (Channel stable, 3.13.7, on macOS 13.0 22A380 darwin-arm64, locale
        en-NG)
        • Flutter version 3.13.7 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2f708eb839 (3 days ago), 2023-10-09 09:58:08 -0500
        • Engine revision a794cf2681
        • Dart version 3.1.3
        • DevTools version 2.25.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E300c
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio
          Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build
          17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.82.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (4 available)
        • sdk gphone64 arm64 (mobile) • emulator-5556                        •
          android-arm64  • Android 14 (API 34) (emulator)
        • iPhone XS (mobile)          • 3CFD1268-0D52-486E-A12E-6E136E972D94 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • macOS (desktop)             • macos                                •
          darwin-arm64   • macOS 13.0 22A380 darwin-arm64
        • Chrome (web)                • chrome                               •
          web-javascript • Google Chrome 117.0.5938.149
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    [✓] Flutter (Channel master, 3.16.0-10.0.pre.72, on macOS 13.0 22A380 darwin-arm64, locale en-NG)
        • Flutter version 3.16.0-10.0.pre.72 on channel master at /Users/damilolaalimi/fvm/versions/master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d479b5e2c6 (72 minutes ago), 2023-10-13 03:35:07 -0400
        • Engine revision b59d779d4f
        • Dart version 3.3.0 (build 3.3.0-20.0.dev)
        • DevTools version 2.28.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E300c
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.82.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (4 available)
        • sdk gphone64 arm64 (mobile) • emulator-5556                        • android-arm64  • Android 14 (API 34) (emulator)
        • iPhone XS (mobile)          • 3CFD1268-0D52-486E-A12E-6E136E972D94 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.0 22A380 darwin-arm64
        • Chrome (web)                • chrome                               • web-javascript • Google Chrome 117.0.5938.149
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    

  6. changed the title [-]dart-define not working with info.plist variables anymore[/-] [+]dart-define not working with info.plist variables[/+] on Oct 13, 2023
  7. added
    platform-iosiOS applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Oct 13, 2023
  8. christopherfujino commented on Oct 17, 2023

    @christopherfujino
    Contributor

    @andrewkolos to possibly de-dupe this with another issue

  9. andrewkolos commented on Oct 17, 2023

    @andrewkolos
    Contributor

    This is nearly a dupe of #130599. I suspect this is caused by this code. With --dart-define, we encode them all into one b64 string and pass them to the build environment as a single property/variable. However, with --dart-define-from-file we pass them individually.

    I will keep this issue open as the Xcode counterpart of #130599. I will rename the other issue to focus on Android.

  10. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Oct 17, 2023
  11. changed the title [-]dart-define not working with info.plist variables[/-] [+]`--dart-define-from-file` entries are available in the environment during Xcode build when they should not be[/+] on Oct 17, 2023
  12. andrewkolos commented on Oct 17, 2023

    @andrewkolos
    Contributor

    @felixmede Sorry, I forgot to actually address your issue in my most recent comment. To summarize, reading --dart-define or --dart-define-from-file values in the environment during Xcode (or Gradle) build, to my knowledge, is not a supported use case. The key-value pairs given to --dart-define or --dart-define-from-file are only meant to be accessible in Dart code (per the help text).

  13. koji-1009 commented on Nov 20, 2023

    @koji-1009
    Contributor

    I have noticed that flutter 3.17.0 (beta) is unable to retrieve the values defined in dart-define-from-file. I understand that this behavior is unintentional.

    Could you please tell me about an alternative approach to switching native settings? I would like to have an easy way to switch bundle ID for iOS, applicationIdSuffix for Android, build flavor, etc. during development, QA and release.
    This is common (I think) in development with Android and iOS SDKs and is needed by stakeholders. This is a risk due to Flutter updates and I'm looking for a way to fix it.

    Thanks.

  14. andrewkolos commented on Nov 20, 2023

    @andrewkolos
    Contributor

    Could you please tell me about an alternative approach to switching native settings?

    Of course! If your native build configurations are reading from the system environment, then you could always set those through other means (e.g. export key=value in your build script).

    I would like to have an easy way to switch bundle ID for iOS, applicationIdSuffix for Android, build flavor, etc. during development, QA and release.

    This sounds like something Flutter's flavors feature is well-suited for. You can define different native build configs and have Flutter choose one of them at build time using the --flavor option on the flutter run and flutter build commands. The examples in the documentation demonstrate how to set up different flavors that will set the bundle ID or applicationIdSuffix appropriately.

    Thanks for the well-written questions.

    I will be closing this issue since it was meant to be closed by #136865, which has already been merged. If I was unclear or you still have concerns, you can reach out via the #hackers-tool channel in the Flutter Discord server, or you can file another issue that references this one.

  15. added
    r: fixedIssue is closed as already fixed in a newer version
    on Nov 21, 2023
  16. TatsuUkraine commented on Nov 21, 2023

    @TatsuUkraine

    Flavors doesn't give same flexibility that you can get with passing env variables from file directly into the native config (including gradle). Don't know why such useful feature marked as bug😕

  17. mobikats commented on Nov 30, 2023

    @mobikats

    This sounds like something Flutter's flavors feature is well-suited for.

    The problem is that the flavors approach becomes complicated and fragile when you have a more complete project that has multiple targets and includes custom extensions (for example supporting "share to" features for iOS and Android, and being able to deliver multiple apps from the same code base with adaptions for different clients).

    The dart-define-from-file approach felt cleaner to use, because you keep the native projects with a single target and extensions, and change only the specific elements required by your separate outputs.

  18. github-actions commented on Dec 14, 2023

    @github-actions

    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 flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions