Repository navigation
--dart-define-from-file entries are available in the environment during Xcode build when they should not be #136444
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- create a flutter project with IOS support
- change the "CFBundleDisplayName" in the Info.plist of the runner to use a new variable
- 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
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!Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Activity
dam-ease commentedon Oct 12, 2023
Hi @felixmede. Thanks for filing this, I cloned your project, ran the app and set the variable using
--dart-defineand 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?fstotz commentedon Oct 13, 2023
If I am running
flutter run lib/main.dart --dart-define=DEFINEEXAMPLE_APP_NAME=testnamethe app name is RunnerIf I am running
flutter run lib/main.dart --dart-define-from-file=config.jsonthe app name is awesomeApp1I think it started to happen after I upgraded to the newest version of Xcode
dam-ease commentedon Oct 13, 2023
Thanks for your response @felixmede. I thought you were describing a crash earlier. I can see this on the latest
masterandstablechannels. 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
[-]dart-define not working with info.plist variables anymore[/-][+]dart-define not working with info.plist variables[/+]christopherfujino commentedon Oct 17, 2023
@andrewkolos to possibly de-dupe this with another issue
andrewkolos commentedon Oct 17, 2023
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-filewe 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.
[-]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[/+]andrewkolos commentedon Oct 17, 2023
@felixmede Sorry, I forgot to actually address your issue in my most recent comment. To summarize, reading
--dart-defineor--dart-define-from-filevalues in the environment during Xcode (or Gradle) build, to my knowledge, is not a supported use case. The key-value pairs given to--dart-defineor--dart-define-from-fileare only meant to be accessible in Dart code (per the help text).do not include entries from `--dart-define-from-file` files in the gr…
koji-1009 commentedon Nov 20, 2023
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.
andrewkolos commentedon Nov 20, 2023
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=valuein your build script).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
--flavoroption on theflutter runandflutter buildcommands. 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.
TatsuUkraine commentedon Nov 21, 2023
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😕
mobikats commentedon Nov 30, 2023
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.
github-actions commentedon Dec 14, 2023
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 -vand a minimal reproduction of the issue.