Skip to content

flutter build ios-framework Some plugin debug framework creation failing #63508

@robrichardson13

Description

@robrichardson13

Issue

So after tons of debugging, I figured out that some plugin packages (native iOS pods) fail to properly create their respective frameworks (in debug) if in their Podspec their name differs from their module name. An example would be a pod with the following spec:

Pod::Spec.new do |s|
s.name = 'Mixpanel-swift'
s.module_name = 'Mixpanel'

Steps to Reproduce

  1. Create a new flutter module: flutter create --template module my_flutter
  2. In the modules pubspec.yaml add the following dependency: native_mixpanel: ^0.1.2 (this uses the Mixpanel-swift pod which has the module/name differences)
  3. Run flutter pub get
  4. Because this package requires target 9.0 and Swift 5.0 isnt declared we have to make some small modifications (step 5 and step 6)
  5. Edit .ios/Podfile and change platform :ios, '8.0' to platform :ios, '9.0'.
  6. Open the demo project in Xcode open .ios/Runner.xcworkspace/. Click on the Runner project on the left, then click on the Runner target. From there click Build Settings and click on the + to add a new Add User-Defined Setting. Type in SWIFT_VERSION for the property and 5.0 for the value.
  7. Run flutter build ios-framework --no-release --no-profile --no-universal --xcframework --verbose

Logs

[   +1 ms] executing: [/my_flutter/build/ios/framework/] xcrun xcodebuild -create-xcframework -framework
/my_flutter/build/ios/framework/Debug/iphoneos/Debug-iphoneos/Mixpanel-swift/Mixpanel.framework -framework
/my_flutter/build/ios/framework/Debug/iphonesimulator/Debug-iphonesimulator/Mixpanel/Mixpanel.framework -output
/my_flutter/build/ios/framework/Debug/Mixpanel.xcframework
[ +467 ms] error: unable to read the file at '/my_flutter/build/ios/framework/Debug/iphonesimulator/Debug-iphonesimulator/Mixpanel/Mixpanel.framework/Mixpanel'

You can see that Debug-iphonesimulator/Mixpanel/Mixpanel.framework/Mixpanel doesnt exist because it actually exists at path: Debug-iphonesimulator/Mixpanel-swift/Mixpanel.framework/Mixpanel instead.

Solution

This problem occurs because when building debug frameworks, it assumes the Pod name and module name match, which causes the file to not be found. This happens in 2 spots in this file build_ios_framework.dart here:

if (mode == BuildMode.debug)
    simulatorBuildConfiguration
        .childDirectory(binaryName)
        .childDirectory(podFrameworkName)
        .childFile(binaryName)
        .path,

A fix would be adding this variable:

final String frameworkDir = globals.fs.path.basename(podProduct.dirname);

and using it in the debug path:

if (mode == BuildMode.debug)
    simulatorBuildConfiguration
        .childDirectory(binaryName)
        .childDirectory(frameworkDir)
        .childFile(binaryName)
        .path,

Here is a diff on the file changes:
Screen Shot 2020-08-11 at 11 58 27 AM

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.1, on Mac OS X 10.15.6 19G73, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.47.3)
[✓] Connected device (1 available)

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: existing-appsIntegration with existing apps via the add-to-app flowfound in release: 1.20Found to occur in 1.20has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyt: xcode"xcodebuild" on iOS and general Xcode project managementtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions