Make it easier to use CocoaPods to Add2App for iOS (#23021)
* Make it easier to Add2App for iOS * Use local engine if xcconfig says so * newline
This commit is contained in:
@@ -88,15 +88,24 @@ BuildApp() {
|
||||
|
||||
RunCommand rm -rf -- "${derived_dir}/App.framework"
|
||||
|
||||
local local_engine_flag=""
|
||||
local flutter_framework="${framework_path}/Flutter.framework"
|
||||
local flutter_podspec="${framework_path}/Flutter.podspec"
|
||||
if [[ -n "$LOCAL_ENGINE" ]]; then
|
||||
local_engine_flag="--local-engine=${LOCAL_ENGINE}"
|
||||
flutter_framework="${LOCAL_ENGINE}/Flutter.framework"
|
||||
flutter_podspec="${LOCAL_ENGINE}/Flutter.podspec"
|
||||
fi
|
||||
|
||||
if [[ -e "${project_path}/.ios" ]]; then
|
||||
RunCommand rm -rf -- "${derived_dir}/engine"
|
||||
mkdir "${derived_dir}/engine"
|
||||
RunCommand cp -r -- "${framework_path}/Flutter.podspec" "${derived_dir}/engine"
|
||||
RunCommand cp -r -- "${framework_path}/Flutter.framework" "${derived_dir}/engine"
|
||||
RunCommand cp -r -- ${flutter_podspec} "${derived_dir}/engine"
|
||||
RunCommand cp -r -- ${flutter_framework} "${derived_dir}/engine"
|
||||
RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -exec chmod a-w "{}" \;
|
||||
else
|
||||
RunCommand rm -rf -- "${derived_dir}/Flutter.framework"
|
||||
RunCommand cp -r -- "${framework_path}/Flutter.framework" "${derived_dir}"
|
||||
RunCommand cp -r -- ${flutter_framework} "${derived_dir}"
|
||||
RunCommand find "${derived_dir}/Flutter.framework" -type f -exec chmod a-w "{}" \;
|
||||
fi
|
||||
|
||||
@@ -110,10 +119,6 @@ BuildApp() {
|
||||
fi
|
||||
|
||||
local build_dir="${FLUTTER_BUILD_DIR:-build}"
|
||||
local local_engine_flag=""
|
||||
if [[ -n "$LOCAL_ENGINE" ]]; then
|
||||
local_engine_flag="--local-engine=$LOCAL_ENGINE"
|
||||
fi
|
||||
|
||||
local track_widget_creation_flag=""
|
||||
if [[ -n "$TRACK_WIDGET_CREATION" ]]; then
|
||||
@@ -296,6 +301,44 @@ ThinAppFrameworks() {
|
||||
done
|
||||
}
|
||||
|
||||
# Adds the App.framework as an embedded binary and the flutter_assets as
|
||||
# resources.
|
||||
EmbedFlutterFrameworks() {
|
||||
AssertExists "${FLUTTER_APPLICATION_PATH}"
|
||||
|
||||
# Prefer the hidden .ios folder, but fallback to a visible ios folder if .ios
|
||||
# doesn't exist.
|
||||
local flutter_ios_out_folder="${FLUTTER_APPLICATION_PATH}/.ios/Flutter"
|
||||
if [[ ! -d ${flutter_ios_out_folder} ]]; then
|
||||
flutter_ios_out_folder="${FLUTTER_APPLICATION_PATH}/ios/Flutter"
|
||||
fi
|
||||
|
||||
AssertExists "${flutter_ios_out_folder}"
|
||||
|
||||
# Copy the flutter_assets to the Application's resources.
|
||||
AssertExists "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
|
||||
RunCommand cp -r -- "${flutter_ios_out_folder}/flutter_assets" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
|
||||
|
||||
# Embed App.framework from Flutter into the app (after creating the Frameworks directory
|
||||
# if it doesn't already exist).
|
||||
local xcode_frameworks_dir=${BUILT_PRODUCTS_DIR}"/"${PRODUCT_NAME}".app/Frameworks"
|
||||
RunCommand mkdir -p -- "${xcode_frameworks_dir}"
|
||||
RunCommand cp -Rv -- "${flutter_ios_out_folder}/App.framework" "${xcode_frameworks_dir}"
|
||||
|
||||
# Embed the actual Flutter.framework that the Flutter app expects to run against,
|
||||
# which could be a local build or an arch/type specific build.
|
||||
# Remove it first since Xcode might be trying to hold some of these files - this way we're
|
||||
# sure to get a clean copy.
|
||||
RunCommand rm -rf -- "${xcode_frameworks_dir}/Flutter.framework"
|
||||
RunCommand cp -Rv -- "${flutter_ios_out_folder}/engine/Flutter.framework" "${xcode_frameworks_dir}/"
|
||||
|
||||
# Sign the binaries we moved.
|
||||
local identity="${EXPANDED_CODE_SIGN_IDENTITY_NAME:-$CODE_SIGN_IDENTITY}"
|
||||
|
||||
RunCommand codesign --force --verbose --sign "${identity}" -- "${xcode_frameworks_dir}/App.framework/App"
|
||||
RunCommand codesign --force --verbose --sign "${identity}" -- "${xcode_frameworks_dir}/Flutter.framework/Flutter"
|
||||
}
|
||||
|
||||
# Main entry point.
|
||||
|
||||
# TODO(cbracken): improve error handling, then enable set -e
|
||||
@@ -309,5 +352,7 @@ else
|
||||
BuildApp ;;
|
||||
"thin")
|
||||
ThinAppFrameworks ;;
|
||||
"embed")
|
||||
EmbedFlutterFrameworks ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user