如何使用Fastlane缩短Flutter iOS应用的构建时间

时间:2019-05-11 11:15:20

标签: ios xcode flutter fastlane bitrise

我的问题是,当使用Firebase(特别是cloud_firestore时,Flutter iOS应用的构建时间太长了,以至于我在Bitrise上构建的CI达到了超时(flutter build --release为28分钟,甚至更多) Fastlane的build_ios_app比20分钟要多)。因此,我无法在CI上执行完整的iOS构建。当然可以进行缓存,但是首先必须完成初始构建:/

根据this guide,在使用Fastlane与Xcode进行归档时,有必要重建iOS应用。但是,a discussion on official Github repo涉及引入直接从Flutter发布IPA文件的命令,但是目前这是不可能的。

我的问题是-有什么方法可以缩短构建时间,例如通过跳过fastlane步骤中的构建,而只是将.app文件辞职和存档到.ipa?我不能自己做。

Here you may find a sample Flutter app启用了cloud_firestore

下面您可以找到我的Bitrise和fastlane配置:

---
format_version: '7'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: flutter
trigger_map:
- push_branch: master
workflow: test
workflows:
prepare:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - set-env-var@0.9.1:
        title: APP_NAME
        inputs:
        - destination_keys: APP_NAME
        - value: pl.flutter.buildTimeIssue
    - set-env-var@0.9.1:
        title: FL_BUILD_NUMBER
        inputs:
        - destination_keys: FL_BUILD_NUMBER
        - value: "$BITRISE_BUILD_NUMBER"
    - set-env-var@0.9.1:
        title: FL_VERSION_NUMBER
        inputs:
        - destination_keys: FL_VERSION_NUMBER
        - value: 0.1.$BITRISE_BUILD_NUMBER
    - git-clone@4.0.14: {}
    - cache-pull: {}
    - recursive-touch@0.9.0: {}
    - flutter-installer:
        inputs:
        - version: v1.2.1
    - script@1.1.5:
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            cd $BITRISE_FLUTTER_PROJECT_LOCATION/ios
            pod repo update
        title: Update pods repository
test:
    before_run:
    - prepare
    steps:
    - flutter-build@0.9.2:
        inputs:
        - project_location: "$BITRISE_FLUTTER_PROJECT_LOCATION"
        - ios_additional_params: "--release --no-codesign -t lib/main.dart
            --build-name=$FL_VERSION_NUMBER --build-number=$FL_BUILD_NUMBER"
        is_always_run: true
    - fastlane@2.4.0:
        title: fastlane iOS
        inputs:
        - work_dir: "$BITRISE_FLUTTER_PROJECT_LOCATION/ios"
        - lane: ios test
    after_run:
    - finish
    envs:
    - opts:
        is_expand: false
    FLAVOR: tst
    - opts:
        is_expand: false
    TARGET_FILE: main_tst
finish:
    steps:
    - cache-push@2.1.1:
        inputs:
        - ignore_check_on_paths: "~/Library/Developer/Xcode/DerivedData"
        - cache_paths: |-
            $BITRISE_FLUTTER_PROJECT_LOCATION/build
            $BITRISE_FLUTTER_PROJECT_LOCATION/ios/Pods
            ~/Library/Developer/Xcode/DerivedData
app:
envs:
- opts:
    is_expand: false
    BITRISE_FLUTTER_PROJECT_LOCATION: ./
- opts:
    is_expand: false
    BITRISE_PROJECT_PATH: ./ios/Runner.xcworkspace
- opts:
    is_expand: false
    BITRISE_SCHEME: tst
- opts:
    is_expand: false
    BITRISE_EXPORT_METHOD: ad-hoc

这是快车道:

default_platform(:ios)

platform :ios do
  lane :test do
    match(
      type: "adhoc",
      force_for_new_devices: true,
    )
    automatic_code_signing(
      use_automatic_signing: false
    )
    update_project_provisioning(
      profile: ENV["sigh_pl.flutter.buildTimeIssue_adhoc_profile-path"],
      build_configuration: "Release",
      code_signing_identity: "iPhone Distribution"
    )
    build_app(
      scheme: "tst",
      configuration: "Release",
      xcargs: "-allowProvisioningUpdates",
      export_options: {
        signingStyle: "manual",
        method: "ad-hoc",
        provisioningProfiles: {
          "pl.flutter.buildTimeIssue": "match AdHoc pl.flutter.buildTimeIssue"
        }
      },
      output_name: "Runner.ipa"
    )
    appcenter_upload(
      app_name: "Name",
      owner_name: "Owner",
      group: "All-users-of-Name",
      ipa: "Runner.ipa"
    )
  end
end

1 个答案:

答案 0 :(得分:1)

我遇到了与https://github.com/invertase/firestore-ios-sdk-frameworks中的Cloud Firestore框架的预编译二进制文件修复的问题,如下所示:

# ...
target 'Runner' do
  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '6.26.0'

# ...
end

此处https://github.com/FirebaseExtended/flutterfire/issues/2751

中有完整的说明