[英]Flutter iOS build fail on running pod install
我正在尝试制作一个 flutter 插件,所以我按照 https://flutter.dev/docs/development/packages-and-plugins/developing-packages上提供的步骤创建了一个插件。 当我尝试运行 ios 示例时出现错误。 下面是我在运行 ios 示例应用程序时得到的日志。
谁能帮我这个?
Running pod install...
CocoaPods' output:
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
Fetching external sources
-> Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
-> Fetching podspec for `flutter_plugin` from `.symlinks/plugins/flutter_plugin/ios`
Resolving dependencies of `Podfile`
Comparing resolved specification to the sandbox manifest
A Flutter
A flutter_plugin
Downloading dependencies
-> Installing Flutter (1.0.0)
-> Installing flutter_plugin (0.0.1)
- Running pre-install hooks
[!] Unable to determine Swift version for the following pods:
- `flutter_plugin` does not specify a Swift version and none of the targets (`Runner`) integrating it has 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.
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:115:in `verify_swift_pods_swift_version'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:37:in `validate!'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:459:in `validate_targets'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:138:in `install!'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/command/install.rb:48:in `run'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'
Error output from CocoaPods:
[33mWARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
Error running pod install
通过将 flutter 和 CocoaPods 更新到最新版本然后运行以下命令来修复
flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec
如果您使用的是 Apple Silicon Chip (M1),则可以执行此操作。
pod cache clean --all
Pod clean
pod deintegrate
sudo gem install cocoapods-deintegrate cocoapods-clean
sudo arch -x86_64 gem install ffi
arch -x86_64 pod repo update
arch -x86_64 pod install
得到了问题。 当我们在终端上通过命令创建插件时,它会为 Android 创建一个默认 Java 和 iOS 的 Objective-C 插件。 可以使用命令将其更改为 Kotlin for Android 和 Swift for iOS,但它将仅添加对根文件夹中的android/
和ios/
支持。 这不会更改example/
目录中的示例代码。 提供的示例仍然是 Java for Android 和 Objective-C for iOS。 然后我从 Android Studio 创建了一个插件,我通过选中“包含 Swift 对 ios 代码的支持”选项创建了对 iOS 的 Swift 支持,它创建了一个使用 swift 而不是 Objective-C 的示例。 那么问题就解决了。
您需要设置 Swift 版本,因为flutter_plugin did not specify a Swift version by default
在你的ios/Podfile
添加
config.build_settings['SWIFT_VERSION'] = '4.1' # required by simple_permission
以下列方式:
target 'Runner' do
use_frameworks! # required by simple_permission
...
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' # required by simple_permission
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
每次将我的项目从一台电脑换到另一台电脑时,我都会遇到这个问题,
我按照这个步骤来解决这个问题,
1.
Delete podfile.lock
2.替换这个
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
和
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
end
flutter_additional_ios_build_settings(target)
end
end
3.运行
flutter clean
flutter run
我在项目级别名称 SWIFT-VERSION 上为 Runner 添加了一个用户定义的构建设置。 没有其他东西对我有用。
不要担心。 有一个简单的解决方案。 创建此文件 - AppResources/iOS/Podfile并将其添加到文件中
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
end
end
这就是您项目的 SWIFT_VERSION 已设置。
我也遇到了这个问题。 然后我意识到这是“pod install”的问题。 并在这里找到了解决方案https://github.com/CocoaPods/CocoaPods/issues/10723
sudo arch -x86_64 gem install ffi
并运行:
arch -x86_64 pod install
代替
pod install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.