From 784cebbdea3d04c9e8a6f96127bffe8f9aff1929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1ja=20Li=C5=A1kov=C3=A1?= Date: Sat, 24 Jul 2021 12:03:06 -0500 Subject: [PATCH 1/2] Create a build script for iOS --- README.md | 8 ++++- scripts/build-ios.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 scripts/build-ios.sh diff --git a/README.md b/README.md index 334b6442..ad30cfe1 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,13 @@ sudo apt install ninja-build ### iOS / iPadOS -* With xcode you can't build a release version without our cert. :-/ Use `flutter run --profile` to have a working version on your iOS device. +* Have a Mac with Xcode installed, and set up for Xcode-managed app signing +* If you want automatic app installation to connected devices, make sure you have Apple Configurator installed, with the Automation Tools (`cfgutil`) enabled +* Set a few environment variables + * FLUFFYCHAT_NEW_TEAM: the Apple Developer team that your certificates should live under + * FLUFFYCHAT_NEW_GROUP: the group you want App IDs and such to live under (ie: com.example.fluffychat) + * FLUFFYCHAT_INSTALL_IPA: set to `1` if you want the IPA to be deployed to connected devices after building, otherwise unset +* Run `./scripts/build-ios.sh` ### Web diff --git a/scripts/build-ios.sh b/scripts/build-ios.sh new file mode 100755 index 00000000..0151f3a9 --- /dev/null +++ b/scripts/build-ios.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +FLUFFYCHAT_ORIG_GROUP="im.fluffychat" +FLUFFYCHAT_ORIG_TEAM="4NXF6Z997G" +#FLUFFYCHAT_NEW_GROUP="com.example.fluffychat" +#FLUFFYCHAT_NEW_TEAM="ABCDE12345" + +# In some cases (ie: running beta XCode releases) some pods haven't updated their minimum version +# but XCode will reject the package for using too old of a minimum version. +# This will fix that, but. Well. Use at your own risk. +# export I_PROMISE_IM_REALLY_SMART=1 + +# If you want to automatically install the app +# export FLUFFYCHAT_INSTALL_IPA=1 + +### Rotate IDs ### +[ -n "${FLUFFYCHAT_NEW_GROUP}" ] && { + # App group IDs + sed -i "" "s/group.${FLUFFYCHAT_ORIG_GROUP}.app/group.${FLUFFYCHAT_NEW_GROUP}.app/g" "ios/FluffyChat Share/FluffyChat Share.entitlements" + sed -i "" "s/group.${FLUFFYCHAT_ORIG_GROUP}.app/group.${FLUFFYCHAT_NEW_GROUP}.app/g" "ios/Runner/Runner.entitlements" + sed -i "" "s/group.${FLUFFYCHAT_ORIG_GROUP}.app/group.${FLUFFYCHAT_NEW_GROUP}.app/g" "ios/Runner.xcodeproj/project.pbxproj" + # Bundle identifiers + sed -i "" "s/${FLUFFYCHAT_ORIG_GROUP}.app/${FLUFFYCHAT_NEW_GROUP}.app/g" "ios/Runner.xcodeproj/project.pbxproj" +} +[ -n "${FLUFFYCHAT_NEW_TEAM" ] && { + # Code signing team + sed -i "" "s/${FLUFFYCHAT_ORIG_TEAM}/${FLUFFYCHAT_NEW_TEAM}/g" "ios/Runner.xcodeproj/project.pbxproj" +} +cat << EOHELP +If something later in the build explodes, and looks possibly related to App IDs: +1. Ask Xcode nicely + - Open ios/Runner.xcodeproj in Xcode + - Go to the Signing & Capabilities tab + - Ask it to repair the certificates/register app IDs/etc +2. Fix it yourself + - Go to https://developer.apple.com/account/resources/identifiers/list + - Ensure that Xcode created the App ID successfully (for fluffychat.app and fluffychat.app.FluffyChat-Share) + - Under "App Groups", make sure it registered your group + - Back "App IDs", check that the App Group was added to each App ID's entitlements +EOHELP + +### [optional] override pods minimum iphoneos deployment target ### +[ -n ${I_PROMISE_IM_REALLY_SMART} ] && { +# 1. I'm sorry about the indentation't ;_; heredocs are weird about it +# 2. The patch basically just removes any preference on target iOS version +# This lets our default from ios/Flutter/AppFrameworkInfo.plist take precendence +cat << EOPATCH | patch --forward --reject-file=apple_please_fix_your_coreutils --silent ios/Podfile +diff --git a/ios/Podfile b/ios/Podfile +index 9411102b..0446120a 100644 +--- a/ios/Podfile ++++ b/ios/Podfile +@@ -37,5 +37,8 @@ end + post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) ++ target.build_configurations.each do |config| ++ config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' ++ end + end + end +EOPATCH +rm -f apple_please_fix_your_coreutils +} + +### Make release build ### +flutter build ipa --release + +### [optional] Install release build ### +[ -n ${FLUFFYCHAT_INSTALL_IPA} ] && { + TMPDIR=$(mktemp -d) + # 1. Turn the xcarchive that flutter created into a dev-signed IPA + echo '{"compileBitcode":false,"method":"development"}' | plutil -convert xml1 -o "${TMPDIR}/options.plist" - + xcodebuild -exportArchive -archivePath ./build/ios/archive/Runner.xcarchive -exportPath "${TMPDIR}" -exportOptionsPlist "${TMPDIR}/options.plist" + # 2. ...and install it on your connected devices + cfgutil --foreach install-app "${TMPDIR}/fluffychat.ipa" + rm -rf "${TMPDIR}" +} From 7dd6e647dc741890e9856efe586cc11b5b1bfd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1ja=20Li=C5=A1kov=C3=A1?= Date: Sat, 24 Jul 2021 19:02:16 -0500 Subject: [PATCH 2/2] Shell script is not my favourite language. --- scripts/build-ios.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/build-ios.sh b/scripts/build-ios.sh index 0151f3a9..9ea2c8c9 100755 --- a/scripts/build-ios.sh +++ b/scripts/build-ios.sh @@ -21,7 +21,8 @@ FLUFFYCHAT_ORIG_TEAM="4NXF6Z997G" # Bundle identifiers sed -i "" "s/${FLUFFYCHAT_ORIG_GROUP}.app/${FLUFFYCHAT_NEW_GROUP}.app/g" "ios/Runner.xcodeproj/project.pbxproj" } -[ -n "${FLUFFYCHAT_NEW_TEAM" ] && { + +[ -n "${FLUFFYCHAT_NEW_TEAM}" ] && { # Code signing team sed -i "" "s/${FLUFFYCHAT_ORIG_TEAM}/${FLUFFYCHAT_NEW_TEAM}/g" "ios/Runner.xcodeproj/project.pbxproj" } @@ -39,7 +40,7 @@ If something later in the build explodes, and looks possibly related to App IDs: EOHELP ### [optional] override pods minimum iphoneos deployment target ### -[ -n ${I_PROMISE_IM_REALLY_SMART} ] && { +[ -n "${I_PROMISE_IM_REALLY_SMART}" ] && { # 1. I'm sorry about the indentation't ;_; heredocs are weird about it # 2. The patch basically just removes any preference on target iOS version # This lets our default from ios/Flutter/AppFrameworkInfo.plist take precendence @@ -65,7 +66,7 @@ rm -f apple_please_fix_your_coreutils flutter build ipa --release ### [optional] Install release build ### -[ -n ${FLUFFYCHAT_INSTALL_IPA} ] && { +[ -n "${FLUFFYCHAT_INSTALL_IPA}" ] && { TMPDIR=$(mktemp -d) # 1. Turn the xcarchive that flutter created into a dev-signed IPA echo '{"compileBitcode":false,"method":"development"}' | plutil -convert xml1 -o "${TMPDIR}/options.plist" -