Flutter fastlane ios how to pass --dart-define - ios

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?

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

Related

"dart: Command not found" when running Dart commands in Codemagic

when I try to run Dart commands (even simple dart --version) in Codemagic it fails with an error saying dart: command not found.
to overcome the issue you need to update your scripts to run $FLUTTER_ROOT/bin/dart instead.
There is no separate Dart SDK on Codemagic build machines, only Flutter SDK and you can use the Dart version shipped with Flutter.
For instance
#!/bin/sh
$FLUTTER_ROOT/bin/dart --version

Flutter iOS build on the App Center fails with error: "Invalid Podfile file: Generated.xcconfig must exist

I've just set up my app to be built on the App Center, by following the article here.
Although the Android version builds and deploys fine on App Center, I'm getting an error with the iOS build, shown in the excerpt from the build output below:
==============================================================================
Task : CocoaPods
Description : Install CocoaPods dependencies for Swift and Objective-C Cocoa projects
Version : 0.151.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/cocoapods
==============================================================================
[command]/usr/local/lib/ruby/gems/2.6.0/bin/pod --version
1.9.1
[command]/usr/local/lib/ruby/gems/2.6.0/bin/pod install --repo-update
[!] Invalid `Podfile` file: Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first.
# from /Users/runner/runners/2.165.2/work/1/s/bdstories/ios/Podfile:51
# -------------------------------------------
# unless File.exist?(generated_xcode_build_settings_path)
> raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
# end
# -------------------------------------------
##[error]The process '/usr/local/lib/ruby/gems/2.6.0/bin/pod' failed with exit code 1
##[error]The 'pod' command failed with error: The process '/usr/local/lib/ruby/gems/2.6.0/bin/pod' failed with exit code 1
##[section]Finishing: Pod install
##[section]Starting: Xcode build (signed)
My build script is:
#!/usr/bin/env bash
# Place this script in project/ios/.
# Fail if any command fails.
set -e
# Debug log.
set -x
cd ..
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter channel beta
flutter doctor
echo "Installed flutter to `pwd`/flutter"
# Build the app.
flutter build ios --release --no-codesign
I did add the flutter pub get as mentioned in the error, but that didn't make a difference. Also worth noting that the build works fine when I do it in Xcode locally. I can also deploy the built archive to Testflight with no problems. It's just the App Center build process I'm having issues with.
I'm a bit lost now and I can't find any information on how to resolve this. I'm also new to CI/CD, so any help appreciated!
Update
I've also tried adding the following to the script to force App Center to run the same version of Cocoapods as my local machine, but it didn't make a difference to the error.
sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.9.1
pod setup
I did this to my post-clone script and it worked:
#!/usr/bin/env bash
#Place this script in project/ios/
echo "Uninstalling all CocoaPods versions"
sudo gem uninstall cocoapods --all --executables
COCOAPODS_VER=`sed -n -e 's/^COCOAPODS: \([0-9.]*\)/\1/p' Podfile.lock`
echo "Installing CocoaPods version $COCOAPODS_VER"
sudo gem install cocoapods -v $COCOAPODS_VER
# fail if any command fails
set -e
# debug log
set -x
pod setup
cd ..
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter channel master
flutter doctor
flutter pub get
echo "Installed flutter to `pwd`/flutter"
flutter build ios --release --no-codesign
The trick seems to have been moving the "fail if any command fails" section to after the pod re-installation
I had the same issue. It happens when the appcenter-post-clone.sh fails to run, so, the flutter is not installed and the command flutter build ios does not run to generate the Generated.xcconfig.
To fix it, I just:
Deleted the appcenter-post-clone and pushed this commit
Opened the configuration of the branch, on Build section. Now the post-clone tag has gone. Save it.
Push another commit with the appcenter-post-clone.sh again.
Configure the branch again, now with the post-clone tag back.
Save & Build.
Check your .gitIgnore. Had the same issue due to the file being excluded from the repo.
Once added back everything went fine.
Be also careful on the Paths defined for Flutter in your project.
1- Navigate to the flutter module directory
2- Do a flutter pub get
** Also make sure that you are on the stable channel "Flutter"
It appears to work now. I think there's been an update to the App Center build process.
For your info, I've included my final post-build script below, in case this is useful:
#!/usr/bin/env bash
#Place this script in project/ios/
# fail if any command fails
set -e
# debug log
set -x
cd ..
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter channel beta
flutter doctor
echo "Installed flutter to `pwd`/flutter"
flutter build ios --release --no-codesign
I encountered the same issue after I copied an existing build profile from another branch. The problem was resolved after deleting the build config and creating a new one from scratch for the target branch.
Try to enter the IOS folder then pod installor
pod update
in the terminal

xcode - command line build - required content for platform watchOS is missing IBBuildSupport

I am trying to build my project (iPad app) from go agent. While building from command line, I am getting below error.
Error log:
Requested but did not find extension point with identifier Xcode.IBBuildSupport.AssetCatalog.AssetTagScanner.TypeExtension
go-agent: error: Initialization failed.
Reason: Required content for platform watchOS is missing
I am not using/referring to any of watchOS related libraries. Any one faced similar kind of error?
This seems to be a problem in GoCD to do with an environment variable that is being set by the GoCD agent.
A Github issue has been opened to fix this.
Meantime, if you have a look at the chat there you'll see that the original reporter has found a workaround, which is to call unset CFProcessPath before invoking the xcodebuild command.
In my case, I changed the custom command I was using to:
unset CFProcessPath; bundle exec fastlane build_for_test
and the build is passing
(I tried using a separate command for the unset CFProcessPath, but the environment variables appear to revert between them - so I was forced to combine the two).

React Native - Xcode Build Using Bad Environment Variabled

I am building a react-native project using "sudo react-native run-ios" command. The build environment variables are acting weird, not returning the expected values such as /Users/userName for $HOME. Instead, I'm getting the following values:
for $USER_LIBRARY_DIR - will result: /var/root/Library
for $HOME - will result /var/root
this is happening ONLY when I build the react project. The Xcode project is compiling smoothly.
Why don't the environment variables return the correct value? I am using a secondary (admin) user on my macbook pro. Might that be related?
Using sudo will make the command run as root, skip the sudo part, delete any build intermediaries and you should be fine.

'Method API not supported on this platform' after Trigger.io update

After Triggerio.io update to v2.2.2 and update of all modules to 'arm64 support' I can't run my app on iphone 5s/6/6+ simulator. None of native modules are working. Each call returns: 'Method API not supported on this platform'.
All other devices are working fine. Any ideas how to fix this?
Cheers
Try forcing a rebuild of your app:
Add the "parameters" module to your app.
Give it a new key/value pair e.g. "bumpme": "1"
Clean out your app's cache directories:
rm -rf .template development
Force a remote rebuild of your app:
forge build ios -f

Resources