From 8171aa86f09d59bed26db66aa8436631b194a269 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 3 Jun 2016 12:20:54 -0700 Subject: [PATCH] Document how to build hello_services for iOS (#4354) This patch adds some sensible defaults to xcode_backend.sh and documents how to build hello_services for iOS using Xcode. --- examples/hello_services/README.md | 25 +++++++++++++++++++++ packages/flutter_tools/bin/xcode_backend.sh | 24 ++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 examples/hello_services/README.md diff --git a/examples/hello_services/README.md b/examples/hello_services/README.md new file mode 100644 index 0000000000..38e2a7ba7e --- /dev/null +++ b/examples/hello_services/README.md @@ -0,0 +1,25 @@ +# Example of using FlutterView in an iOS app. + +This project demonstrates how to embed Flutter within an iOS application +and build the iOS and Flutter components with Xcode. + +## Configure + +Create an `ios/Flutter/Generated.xcconfig` file with this entry: + + * `FLUTTER_ROOT=[absolute path to the Flutter SDK]` + +There are a number of other parameters you can control with this file: + + * `FLUTTER_APPLICATION_PATH`: The path that contains your `pubspec.yaml` file + relative to your `xcodeproj` file. + * `FLUTTER_TARGET`: The path to your `main.dart` relative to your + `pubspec.yaml`. Defaults to `lib/main.dart`. + * `FLUTTER_FRAMEWORK_DIR`: The absolute path to the directory that contains + `Flutter.framework`. Defaults to the `ios-release` version of + `Flutter.framework` in the `bin/cache` directory of the Flutter SDK. + +## Build + +Once you've configured your project, you can open `ios/HelloServices.xcodeproj` +in Xcode and build the project as usual. diff --git a/packages/flutter_tools/bin/xcode_backend.sh b/packages/flutter_tools/bin/xcode_backend.sh index fae90332d4..7af41ce982 100755 --- a/packages/flutter_tools/bin/xcode_backend.sh +++ b/packages/flutter_tools/bin/xcode_backend.sh @@ -23,7 +23,21 @@ AssertExists() { } BuildApp() { - local project_path=${FLUTTER_APPLICATION_PATH} + local project_path="${SOURCE_ROOT}/.." + if [[ -n "$FLUTTER_APPLICATION_PATH" ]]; then + project_path=${FLUTTER_APPLICATION_PATH} + fi + + local target_path="lib/main.dart" + if [[ -n "$FLUTTER_TARGET" ]]; then + target_path=${FLUTTER_TARGET} + fi + + local framework_path="${FLUTTER_ROOT}/bin/cache/artifacts/engine/ios-release" + if [[ -n "$FLUTTER_FRAMEWORK_DIR" ]]; then + framework_path="${FLUTTER_FRAMEWORK_DIR}" + fi + AssertExists ${project_path} local derived_dir=${SOURCE_ROOT}/Flutter @@ -33,9 +47,11 @@ BuildApp() { RunCommand rm -f ${derived_dir}/Flutter.framework RunCommand rm -f ${derived_dir}/app.so RunCommand rm -f ${derived_dir}/app.flx - RunCommand cp -r ${FLUTTER_FRAMEWORK_DIR}/Flutter.framework ${derived_dir} + RunCommand cp -r ${framework_path}/Flutter.framework ${derived_dir} RunCommand pushd ${project_path} + AssertExists ${target_path} + local local_engine_flag="" if [[ -n "$LOCAL_ENGINE" ]]; then local_engine_flag="--local-engine=$LOCAL_ENGINE" @@ -49,7 +65,7 @@ BuildApp() { RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build aot \ --target-platform=ios \ - --target=${FLUTTER_TARGET} \ + --target=${target_path} \ --release \ ${interpreter_flag} \ ${local_engine_flag} @@ -70,7 +86,7 @@ BuildApp() { fi RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build flx \ - --target=${FLUTTER_TARGET} \ + --target=${target_path} \ --output-file=${derived_dir}/app.flx \ ${precompilation_flag} \ ${local_engine_flag} \