Flutter iOS 在 运行 pod 安装上构建失败
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
您需要设置 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
您还可以查看 this github thread and Whosebug 讨论,了解有关发生这种情况的更多详细信息。
知道问题了。当我们在终端上通过命令创建插件时,它会创建一个默认 Java 代表 Android 和 Objective-C 代表 iOS 的插件。可以使用命令将 Android 和 Swift 的 iOS 更改为 Kotlin,但它只会在根目录中添加对 android/
和 ios/
的支持文件夹。这不会更改 example/
目录中的示例代码。提供的示例仍在 Java for Android 和 Objective-C for iOS。然后我从 Android Studio 创建了一个插件,我通过检查选项 'Include Swift support for ios code' 创建了对 iOS 的 Swift 支持,它创建了一个 swift 的示例Objective-C 个。那么问题就解决了。
已通过将 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 M1 芯片,只需卸载 gem
安装的所有 cocoapods
,然后尝试 brew
安装。
sudo gem uninstall cocoapods
brew install cocoapods
然后
flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec
别担心。有一个简单的解决方案。创建此文件 — 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 已设置。
我在项目级别名称 SWIFT-VERSION 上为 Runner 添加了一个用户定义的构建设置。没有别的对我有用。
我也遇到过这个问题。然后我意识到这是“pod install”的问题。并在这里 https://github.com/CocoaPods/CocoaPods/issues/10723
找到了解决方案
sudo arch -x86_64 gem install ffi
和运行:
arch -x86_64 pod install
而不是
pod install
每次我把我的项目从一台电脑换到另一台电脑时,我都会遇到这个问题,
我按照这个步骤来解决这个问题,
1.
Delete podfile.lock
2.replace这个
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.run
flutter clean
flutter run
如果您使用的是 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
我正在尝试制作一个 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
您需要设置 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
您还可以查看 this github thread and
知道问题了。当我们在终端上通过命令创建插件时,它会创建一个默认 Java 代表 Android 和 Objective-C 代表 iOS 的插件。可以使用命令将 Android 和 Swift 的 iOS 更改为 Kotlin,但它只会在根目录中添加对 android/
和 ios/
的支持文件夹。这不会更改 example/
目录中的示例代码。提供的示例仍在 Java for Android 和 Objective-C for iOS。然后我从 Android Studio 创建了一个插件,我通过检查选项 'Include Swift support for ios code' 创建了对 iOS 的 Swift 支持,它创建了一个 swift 的示例Objective-C 个。那么问题就解决了。
已通过将 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 M1 芯片,只需卸载 gem
安装的所有 cocoapods
,然后尝试 brew
安装。
sudo gem uninstall cocoapods
brew install cocoapods
然后
flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec
别担心。有一个简单的解决方案。创建此文件 — 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 已设置。
我在项目级别名称 SWIFT-VERSION 上为 Runner 添加了一个用户定义的构建设置。没有别的对我有用。
我也遇到过这个问题。然后我意识到这是“pod install”的问题。并在这里 https://github.com/CocoaPods/CocoaPods/issues/10723
找到了解决方案sudo arch -x86_64 gem install ffi
和运行:
arch -x86_64 pod install
而不是
pod install
每次我把我的项目从一台电脑换到另一台电脑时,我都会遇到这个问题,
我按照这个步骤来解决这个问题,
1.
Delete podfile.lock
2.replace这个
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.run
flutter clean
flutter run
如果您使用的是 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