我创建了一个小 Flutter 插件,可用于监控 Flutter 应用程序中的位置变化(来源:https://github.com/baseflowit/flutter-geolocator)。在使用作为项目结构一部分的示例项目(由 Flutter CLI 生成)进行广泛测试后,我们决定发布该插件以使其可供全世界使用。
现在我们收到一些反馈,当您将在线 Dart Packages repo 中的包包含到您的 Flutter App 中时,iOS 版本无法编译并返回以下异常:
/Users/maurits/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-0.0.2/ios/Classes/GeolocatorPlugin.m:2:9:
fatal error: 'geolocator/geolocator-Swift.h' file not found
在 Debug模式下运行 Flutter App 时会出现此错误,并且在使用 flutter build ios --release
制作 iOS 包时也会出现此错误。
我有点不知所措,因为作为 Geolocator
项目一部分的 example
应用程序可以正常工作。我知道 geolocator/geolocator-Swift.h
文件是自动生成的,所以在我看来,该文件并没有出现在最终的 Dart 包中。为了运行最终的 Dart 包,我运行了以下命令:
flutter 包发布发布
这是flutter doctor -v
的输出:
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-NL)
• Flutter version 0.5.1 at /Users/maurits/Developer/flutter
• Framework revision c7ea3ca377 (4 weeks ago), 2018-05-29 21:07:33 +0200
• Engine revision 1ed25ca7b7
• Dart version 2.0.0-dev.58.0.flutter-f981f09760
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.0)
• Android SDK at /Users/maurits/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.0
• ANDROID_HOME = /Users/maurits/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.4.1, Build version 9F2000
• ios-deploy 1.9.2
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 25.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[!] VS Code (version 1.24.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected devices (1 available)
• iPhone X • 69C349CF-81E1-47E8-B35A-A149D885CE43 • ios • iOS 11.4 (simulator)
任何帮助将不胜感激。
最佳答案
你去 Ios/Podfile 添加以下行:
use_frameworks! # required by Geolocator
喜欢下面的
准备符号链接(symbolic link)文件夹。我们使用符号链接(symbolic link)来避免 Podfile.lock 指的是开发者机器上的绝对路径。
use_frameworks! # required by Geolocator
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
在此添加之后
config.build_settings['SWIFT_VERSION'] = '4.2'
如下:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['SWIFT_VERSION'] = '4.2' # added this
end
end
end
关于ios - Flutter 插件 `geolocator-Swift.h` 文件未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51056579/
相关文章:
android - Flutter - Image.network 失败时的默认图像
flutter - 如何将小部件动态添加到 Flutter 中的列?
dart - 如何将背景图像添加到 flutter 应用程序?
image - Flutter:如何将 Canvas/CustomPainter 保存到图像文件中?
android - Flutter - 使用正则表达式验证电话号码
flutter - 无法访问 flutter.dev (Mac OS)
amazon-web-services - 如何在不使用原生 SDK 的情况下使用 AWS Cogn
dart - 使用标准库将字符串转换为 Dart 中的 GET 请求参数