Skip to content

Investigate integrating integration_test as Swift package instead of pod #72482

@jmagman

Description

@jmagman

integration_test is currently included in a newly flutter created pubspec. It is embedded in iOS projects via CocoaPods as is normal for a plugin (though really it should only be embedded in a test target, but that's a fixable bug). This means that every project will need to be opted into CocoaPods (currently a dependency only required with plugins), even though integration_test has no pod dependencies and is not even distributed via pub.

This plugin is shipped in the repository proper, so it may instead possible to integrate it into test projects via Swift Package Manager, bypassing CocoaPods completely.

I have a prototype working with a Package.swift file in the root of the Flutter repo:

// swift-tools-version:5.3

import PackageDescription

let package = Package(
  name: "Flutter",
  platforms: [
    .iOS(.v9)
  ],
  products: [
    .library(
      name: "integration_test",
      targets: ["integration_test"]),
  ],
  targets: [
    .target(
      name: "integration_test",
      dependencies: ["Flutter"],
      path: "packages/integration_test/ios",
      exclude: ["integration_test.podspec"],
      sources: ["Classes"],
      publicHeadersPath: "Classes"
    ),
    .binaryTarget(
      name: "Flutter",
      path: "bin/cache/artifacts/engine/ios-release/Flutter.xcframework"),
  ]
)

To test this, drag the flutter repo directory into Frameworks:
Screen Shot 2020-12-16 at 6 03 09 PM

Create a test target with @import integration_test, Link Binary with Libraries, and choose integration_test
Screen Shot 2020-12-16 at 6 03 19 PM
It should then build.

Notes:

  1. The Flutter binaryTarget is required since integration_test imports Flutter. I wasn't able to get any linker tricks working to avoid this.
  2. Since binaryTarget is required, this will only work in Xcode 12+ (Swift 5.3) where the feature was introduced. Currently the minimum Xcode version enforced in the tool is 11.0.
  3. All places where plugins==CocoaPods is assumed needs to be hard coded to avoid integration_test the tool. For example, don't generate a Podfile when it's the only plugin, etc.
  4. integration_test should be removed from GeneratedPluginRegistrant since the app proper should never link on this.
  5. The path to the Package.swift will need to be a property in the Xcode project. The path can't actually be the absolute path to the user's Flutter SDK since that will be different on every machine, and this file is checked in and shared between team members. That probably means creating a symlink to the project to the repo (in ios/.symlinks/flutter?) recreated on every ensureReadyForPlatformSpecificTooling.
F7FA93DA258AEF2200C1C93B /* flutter */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter; path = path/to/flutter; sourceTree = "<group>"; };

Blocked by #57083

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsf: integration_testThe flutter/packages/integration_test plugint: xcode"xcodebuild" on iOS and general Xcode project managementteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions