Flutter: Can't create plugin packages - flutter
I'm trying to create a plugin package in order to access some specific hardware APIs, both in Android (using Kotlin) and in iOS (using Swift). To that end, I was trying to follow the instructions here:
https://flutter.dev/docs/development/packages-and-plugins/developing-packages
I'm right now only working on the Swift side of the problem, so what has been done so far is the following:
1) Went to the directory where other Dart packages live (which are non-Flutter ones, and which work perfectly okay) and ran:
flutter create --org com.example --template=plugin my_plugin
That created the whole thing as described in the documentation, and no error was reported.
2) Then, as stated in the previous link, I went to my_plugin/example and ran flutter build ios --no-codesign, with the following (apparently okay?) output:
Warning: Building for device with codesigning disabled. You will have to manually codesign before deploying to device.
Building com.example.myPluginExample for device (ios-release)...
Running pod install... 6.5s
├─Building Dart code... 2.9s
├─Generating dSYM file... 1.0s
├─Stripping debug symbols... 0.6s
├─Assembling Flutter resources... 1.0s
└─Compiling, linking and signing... 9.0s
Xcode build done. 19.8s
3) So now with the plugin just created, tried to add it to the main project and thus, in its pubspec.yaml file, inserted the following lines (the plugin is located in ../pkgs with respect to the Flutter application I'm working in:
dependencies:
flutter:
sdk: flutter
my_plugin:
path: ../pkgs/my_plugin
4) Now just tried to run the Flutter application both in a physical device and in the simulator, and the following error always showed up:
Launching lib/main.dart on iPhone Xʀ in debug mode...
CocoaPods' output:
↳
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
Finding Podfile changes
A my_plugin
- Flutter
Fetching external sources
-> Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
-> Fetching podspec for `my_plugin` from `.symlinks/plugins/my_plugin/ios`
Resolving dependencies of `Podfile`
Comparing resolved specification to the sandbox manifest
A Flutter
A my_plugin
Downloading dependencies
-> Installing Flutter (1.0.0)
-> Installing my_plugin (0.0.1)
- Running pre install hooks
[!] Unable to determine Swift version for the following pods:
- `my_plugin` does not specify a Swift version and none of the targets (`Runner`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:115:in `verify_swift_pods_swift_version'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:37:in `validate!'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:459:in `validate_targets'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:138:in `install!'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/command/install.rb:48:in `run'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/command.rb:52:in `run'
/usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/bin/pod:55:in `<top (required)>'
/usr/local/Cellar/cocoapods/1.6.1/libexec/bin/pod:22:in `load'
/usr/local/Cellar/cocoapods/1.6.1/libexec/bin/pod:22:in `<main>'
Error output from CocoaPods:
↳
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
export LANG=en_US.UTF-8
Error running pod install
Error launching application on iPhone Xʀ.
Exited (sigterm)
5) I tried to fix it by adding the following line to the only 2 Podfile files that I can see in my whole directory structure (the one that belongs to the app and the one that belongs to the new plugin "example" -both files automatically created by Flutter's tools and both not having received any edit until today-):
config.build_settings['SWIFT_VERSION'] = '4.1'
(that idea was taken from https://stackoverflow.com/a/52194702/6348097, and yes: I tried at least one different version number). The error is still the same.
The resulting plugin's Podfile is:
platform :ios, '9.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
pods_ary = []
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
end
target 'Runner' do
use_frameworks!
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
end
}
# Plugin Pods
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.1'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
I did the same adding to the Flutter app's Podfile. Also, the first line where the iOS platform was specified, was originally commented (and that was generating a warning) so I also uncommented that line from both podfiles.
This is the output of flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.3 18D109, locale en-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2)
[✓] Android Studio (version 3.3)
[✓] VS Code (version 1.33.1)
[✓] Connected device (1 available)
• No issues found!
The question is just how to make this work. I did not even started adding my own code, but I'm stuck with the very basic Flutter's plugin creation tool. Also, I have no idea why I need all that dirty and complex example subdir in my package (so as a secondary question that is not really important: can I just remove it once this works?)
EDIT: I did another test: created an empty app using VSC's "Flutter: New Project" command (which creates the "Flutter 101" increment-a-counter example). Then followed again the steps described above in order to create the plugin package, and got the same error when included that package on the newly created project and ran it in the iOS simulator. So there is absolutely no code from me there, except for having added the new plugin as a dependency to the example app.
Try to open the IOS project in the folder ios/Runner/Runner.xcworkspac with Xcode. Then create / add a new Swift file anywhere in that directory. Xcode will then automatically apply changes needed to your support your swift part of your flutter app.
The other thing could be that your PodFile was modified somehow: try to compare it to Google's master PodFile through this link: PodFile Master File
After having tried several things, none of which worked, I found this solution on a GitHub thread:
https://github.com/ko2ic/image_downloader/issues/9#issuecomment-471608482
Having followed these steps strictly, did finally work.
A few interesting thing were:
I also tried to create the plugin from Android Studio (instead of from the command line or from VSC). It did not work without the steps described in the previous link, but the steps were finally done on that Android Studio created plugin (so I just don't know if this would work with a VSC created plugin, must I would say that most likely yes, since I did not see any difference on the outcome of the commands). I mention this because this answer was suggesting that that may fix the problem: https://stackoverflow.com/a/54919007/6348097
There are 2 Podfile files in the sources: one for the plugin, and another one for the app itself. I modified both and I opened both XCode (automaticall generated) projects.
I also added the following line to the Podfile: config.build_settings['SWIFT_VERSION'] = '4.2', right before the only occurrence of the following line: config.build_settings['ENABLE_BITCODE'] = 'NO'
In both Podfile files, uncommented the platform :ios, '8.0', and changed the versino to 9.0. This did not solve the problem, but at some point fixed a warning when running pod install
Related
Flutter error: xcodebuild: WARNING: Using the first of multiple matching destinations
Flutter version is 2.2.3 and I cant't run de flutter code on my iOS emulator. Launching lib/main.dart on iPhone 13 Pro in debug mode... lib/main.dart:1 Xcode build done. 43.6s Failed to build iOS app Error output from Xcode build: ↳ --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device } { platform:iOS Simulator, id:320795B7-1385-4044-B442-87A9808936D9, OS:15.0, name:iPhone 13 Pro } { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device } { platform:iOS, id:00008101-000825EC3AE1001E, name:leobidoous iPhone, error:Device is busy (Making leobidoous iPhone ready for development, Processing cache files from device, Making the device ready for development) } ** BUILD FAILED ** Xcode's output: ↳ Command PhaseScriptExecution failed with a nonzero exit code note: Using new build system note: Planning note: Build preparation complete note: Building targets in parallel
I had the same problem updating Xcode. Solve just logging back into Xcode. Open Xcode Open the project's Runner.xcworkspace file Log into Xcode at: "Signing & Capabilities" -> "All" -> "Signing" Item 3 was my problem. When updating Xcode, I was logged out.
Adding these lines to Podfile Helped me. target.build_configurations.each do |build_configuration| build_configuration.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64 i386' end Example:
If you use package sign_in_with_apple, it should have 3.2.0 version at least.
put this code in your Podfile post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |build_configuration| build_configuration.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64 i386' end end end
The only solution that worked for me was to completely remove the xcode installed and reinstall from the app store. When removing the old xcode, make sure to remove all the residual files - especially the developer folder. Try these following commands sudo rm -rf ~/Library/Developer/ sudo rm -rf ~/Library/Caches/com.apple.dt.Xcode and remove xcode from Application to bin. Doing this will completely clean the xcode residuals and then you can reinstall from the appstore.
I encountered same issue and by running flutter clean fixed the issue for me. Also try restarting the IDE if this doesn't work.
For me, I am fine after forcing the Simulator.app quit and run the command again.
I faced the same issue for flutter version 2.5.1 stable Previously i installed flutter using Zip archive file now I completely removed that installation and setup it using Git clone I did things like flutter clean, pod clear cache , pod install etc IMP Note in xcode please check developer signing&capabilities options for runner etc I did these and these are worked for me
The relevant part here is Command PhaseScriptExecution failed with a nonzero exit code which means that any of the scripts configured in Xcode > Targets > Runner > (Tab) Build Phases failed. The problem here is that you do not see the error message (which script failed and why). Add the --verbose flag (short: -v) to the flutter run command: flutter run -v This will output a lot. At the end you need to scroll a bit up to the the actual script error. Once you know the actual error, you probably can solve it easily or open a new and more specific question.
I encountered the same error on flutter 2.5.3. Now I downgraded to 2.5.1 and the app is running on my iOS emulator. Try this may help you.
I have solved it by clean the IDEA + flutter clean then restarting Mac then open Xcode from flutter project then clean Xcode build by select product -> Celan Build folder then RUN your project from Xcode to download dependence
Add the below lines to your podfile. Place the below lines in the post_install do [installer] section at the bottom of the Podfile. Code : target.build_configurations.each do |build_configuration| build_configuration.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64 i386' end
All of the answers here, depending on your circumstances, have aspects that absolutely remove this error. For myself, what I can say is that I can confirm that using an 2021 M1 macbook pro max with a fresh set of tools, flutter 2.8.1, dart 1.15.1 and having the following or similar post_install section in my podfile also silenced the offending output. post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf' config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES' config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64 i386' end end end
Try this. This process will re-download ios and android development tools again after running the code through the ios and android simulator. Worked for me Flutter clean Flutter get Flutter channel stable flutter upgrade and restart IDE as well as close Xcode. works for me, I hope this helps
If your project is with firebase and it is cloned and cleaning is not well like me. Probably this can help you. Add GoogleService-Info.plist back to your Runner project. (if already have can ignore) Try to Clean Build Folder on xcode then Build again. Try to build into Simulator using xcode. Try to build into your connected iPhone. If 3 and 4 is working. Back to your vscode then build and run again to iPhone or Simulator
In android studio, Gradle sync Build model taking too long
I'm new to android development and just installed android studio. It's the first time I'm opening studio. Gradle: Build model is taking long time. It's been already 50mins and still continuing and no message in console. I don't know what to do. Please help me.
Do you have a cloud_firestore package? If so, it usually adds to the build compilation time significantly. But you should provide more details - if its android emulator or iOS and your code. If its Firestore Cloud + iOS emulator Improve iOS Build Times# Currently the Firestore iOS SDK depends on some 500k lines of mostly C++ code which can take upwards of 5 minutes to build in XCode. To reduce build times significantly, you can use a pre-compiled version by adding 1 line to your ios/Podfile inside your Flutter project; pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '8.6.0' Add this line inside your target 'Runner' do block in your Podfile, e.g.: # ... target 'Runner' do pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '8.6.0' # ... end Additionally, ensure that you have upgraded your cocoapods to 1.9.1 or higher: gem install cocoapods For more information see this issue: https://github.com/FirebaseExtended/flutterfire/issues/2751
Unable to read the license file `../LICENSE` for the spec `integration_test
I use Flutter with Android studio and when I run The Error output from CocoaPods is shown as below Do you know how to solve the problem? [Screen shot of Android studio] Launching lib/main.dart on iPhone 8 in debug mode... Running pod install... CocoaPods' output: ↳ Preparing . . . . . Error output from CocoaPods: ↳ [!] Automatically assigning platform `ios` with version `9.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`. [!] A license was specified in podspec `integration_test` but the file does not exist - /Users/a/AndroidStudioProjects/flutter_app5/ios/.symlinks/plugins/integration_test/LICENSE [!] Unable to read the license file `../LICENSE` for the spec `integration_test (0.0.1)` [!] Unable to read the license file `../LICENSE` for the spec `integration_test (0.0.1)` Error running pod install Error launching application on iPhone 8.
I have exactly the same issue. The first of them I was able to solve: open your project's Podfile which is located in your project's ios folder and remove the comments in line 2 to e.g. # Uncomment this line to define a global platform for your project platform :ios, '9.0'
First at all, if you use flutter in dev or beta channel, should change it to master or stable. If not, to resolve first issue, open ios/Podfile and uncomment second line # Uncomment this line to define a global platform for your project platform :ios, '9.0' to resolve another issues which relative with integration_test, a simple way is just remove it, open pubspec.yaml, remove below code integration_test: sdk: flutter and give it a try.
Flutter Stopped building for IOS --Error running pod install
Everything was working just fine and all of sudden this happned. I tried following Uninstall Cocoapods Install again Update delete pod.lock file upgrade ruby upgrade gem nothing worked. I tried running other projects too but as soon as I add firebase dependencies I get this error..here Analyzing dependencies firebase_auth: Using Firebase SDK version '6.33.0' defined in 'firebase_core' [!] Failed to load 'firebase_auth' podspec: [!] Invalid `firebase_auth.podspec` file: undefined method `ui' for #<Pod::Specification name="firebase_auth">. /ios/.symlinks/plugins/firebase_auth/ios/firebase_auth.podspec:24 # ------------------------------------------- # s.description = pubspec['description'] > s.ui.homepage = pubspec['ui.homepage'] # s.license = { :file => '../LICENSE' } # ------------------------------------------- Error running pod install
It was an issue of Android studio really. I deleted my project, cloned it from github again and then used Flutter commands in temrinal to run the app on IOS it worked. If I try to run it using android studio it fails still with the same error.
producing flutter (Xcode) testflight archive fails with multiple commands produce
need to produce an archive so we can upload to TestFlight so followed instructions in https://flutter.dev/docs/deployment/ios . my flutter runs on both real iPhone and simulator with no problem. so I produce a release version as required then open the resultant Xcode project (runner). immediately see the error :-1: Multiple commands produce '/Users/jmcfet/Library/Developer/Xcode/DerivedData/Runner-cwxykfeiijpirmgbtrkzktdrahbt/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/Flutter.framework': 1) Target 'Runner' has copy command from '/Users/jmcfet/AndroidStudioProjects/sis/ios/Flutter/Flutter.framework' to '/Users/jmcfet/Library/Developer/Xcode/DerivedData/Runner-cwxykfeiijpirmgbtrkzktdrahbt/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/Flutter.framework' 2) That command depends on command in Target 'Runner': script phase “[CP] Embed Pods Frameworks” now this does not happen when I do the same against the "Flutter Hello world" app so wondering what is messed up in my Flutter app
no luck : johns-MacBook-Air:ios jmcfet$ pod install Analyzing dependencies Fetching podspec for Flutter from .symlinks/flutter/ios Fetching podspec for video_player from .symlinks/plugins/video_player/ios Downloading dependencies Using Flutter (1.0.0) Using video_player (0.0.1) Generating Pods project Integrating client project Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed. [!] Automatically assigning platform ios with version 8.0 on target Runner because no platform was specified. Please specify a platform for this target in your Podfile. See https://guides.cocoapods.org/syntax/podfile.html#platform. [!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target Runner to Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig or include the Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig in your build configuration (Flutter/Release.xcconfig). not an IOS expert but looks like the install was not successful. little confused as the Xcode project was generated by Flutter so why is Flutter generating a bad config file. if so looks like a bug to me