简体   繁体   English

"Flutter fastlane ios如何通过--dart-define"

[英]Flutter fastlane ios how to pass --dart-define

I can't find answer for this.我找不到这个问题的答案。 My app needs parameters defined --dart-define=ENVIRONMENT="$APP_ENV"<\/code>我的应用需要定义参数--dart-define=ENVIRONMENT="$APP_ENV"<\/code>

There is no problem building Android, but how to pass those while build ad-hoc in fastlane?构建 Android 没有问题,但是在 fastlane 中构建 ad-hoc 时如何通过这些? I've prepared build scripts that run:我准备了运行的构建脚本:

flutter pub get
flutter build ios --config-only \ 
    --flavor prod \ 
    --dart-define=ENVIRONMENT="$APP_ENV"

cd ios
bundle exec fastlane build_app_prod_ad_hoc

Solution :解决方案
Encoding and replacing your dart variable in flutter_export_environment.sh and Generated.xcconfig then running the app from Xcode/Fastlane directly will work fine.flutter_export_environment.shGenerated.xcconfig中编码和替换你的 dart 变量,然后直接从 Xcode/Fastlane 运行应用程序就可以了。

------ Details ------- - - - 细节 - - - -

The issue:问题:
The variables passing via --dart-define won't reflect if you run the app from Xcode/ Fastlane directly without first running the flutter run/build command.如果您直接从 Xcode/Fastlane 运行应用程序而不先运行 flutter run/build 命令,则通过 --dart-define 传递的变量不会反映。

Reason:原因:
The following generated files are involved but not intended to update manually, but in our case running from Xcode or Fastlane to build the app, the dart variables used won't get updated.涉及以下生成的文件,但不打算手动更新,但在我们从 Xcode 或 Fastlane 运行来构建应用程序的情况下,使用的 dart 变量不会得到更新。 When you run the flutter run or build command, these files get updated with the values from --dart-define as Base64.当您运行 flutter run 或 build 命令时,这些文件将使用 --dart-define 中的值更新为 Base64。

/ios/Flutter/flutter_export_environment.sh /ios/Flutter/flutter_export_environment.sh
ios/Flutter/Generated.xcconfig ios/Flutter/Generated.xcconfig

在此处输入图像描述

When you directly build the app from Xcode or use Fastlane, the Generated.xcconfig from the ios folder inside the Flutter project code is being used to run/build the app.当您直接从 Xcode 构建应用程序或使用 Fastlane 时,Flutter 项目代码中 ios 文件夹中的 Generated.xcconfig 将用于运行/构建应用程序。

Example: In my case, we pass the ENV variable using --dart-define, but if you run directly from XCode without running the flutter build or run command first, these arguments won't update.示例:在我的例子中,我们使用 --dart-define 传递 ENV 变量,但是如果您直接从 XCode 运行而不先运行 flutter build 或 run 命令,这些参数将不会更新。

flutter run/build --flavor dev --dart-define ENV=dev颤振运行/构建 --flavor dev --dart-define ENV=dev

Dart define variable will store in the flutter_export_environment.sh and Generated.xcconfig in Base64 encoding. Dart 定义变量会以 Base64 编码存储在 flutter_export_environment.sh 和 Generated.xcconfig 中。

DART_DEFINES=RU5WX1UEU9chZ2luZw== DART_DEFINES=RU5WX1UEU9chZ2luZw==

在此处输入图像描述

Note: This is a workaround to avoid running the flutter run/build command followed by a Xcode/Fastlane run to solve the issue.注意:这是一种解决方法,可以避免运行 flutter run/build 命令,然后运行 ​​Xcode/Fastlane 来解决问题。 Not the best solution, but I hope it may help someone.不是最好的解决方案,但我希望它可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM