Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"

There is no problem building Android, but how to pass those while build ad-hoc in fastlane? 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

And my lane for fastlane is:

  lane :build_app_prod_ad_hoc do
    cocoapods
    gym(
      configuration: "AdHoc-prod",
      export_method: "ad-hoc",
      scheme: "prod",
      export_options: {
        provisioningProfiles: {
           ...
        },
      },
    )
  end

But I can see that my result doesn't have ENVIRONMENT set correctly. Any ideas?

like image 823
miszmaniac Avatar asked Oct 16 '20 20:10

miszmaniac


1 Answers

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.

------ 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.

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. When you run the flutter run or build command, these files get updated with the values from --dart-define as Base64.

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

enter image description here

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.

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.

flutter run/build --flavor dev --dart-define ENV=dev

Dart define variable will store in the flutter_export_environment.sh and Generated.xcconfig in Base64 encoding.

DART_DEFINES=RU5WX1UEU9chZ2luZw==

enter image description here

Note: This is a workaround to avoid running the flutter run/build command followed by a Xcode/Fastlane run to solve the issue. Not the best solution, but I hope it may help someone.

like image 55
Praveen Vijayan Avatar answered Nov 15 '22 06:11

Praveen Vijayan