-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
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
- Create a new flutter module:
flutter create --template module my_flutter - In the modules
pubspec.yamladd the following dependency:native_mixpanel: ^0.1.2(this uses theMixpanel-swiftpod which has the module/name differences) - Run
flutter pub get - Because this package requires target
9.0andSwift 5.0isnt declared we have to make some small modifications (step 5 and step 6) - Edit
.ios/Podfileand changeplatform :ios, '8.0'toplatform :ios, '9.0'. - Open the demo project in Xcode
open .ios/Runner.xcworkspace/. Click on theRunnerproject on the left, then click on theRunnertarget. From there clickBuild Settingsand click on the+to add a newAdd User-Defined Setting. Type inSWIFT_VERSIONfor the property and5.0for the value. - 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:

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!