为 flutter (iOS) 添加 image_picker 依赖项时出错
Errors when added image_picker dependency for flutter (iOS)
我需要为我的应用程序使用 image_picker。我在我的 pubspec.yaml 文件中添加了 image_picker 依赖项,对于 iOS 我添加了 NSCameraUsageDescription
NSPhotoLibrary使用说明
NS麦克风使用说明
到 info.plist 文件中,但在 iOS 模拟器上尝试 运行 应用程序时出现此错误。
这是我在尝试 运行 应用程序时遇到的错误。
`在调试模式下在 iPhone 11 Pro Max 上启动 lib/main.dart...
/Users/sirapol/Desktop/FirstCareFrontEnd/care_now_frontend_v1/ios/Runner/Info.plist: 属性 列表错误:在里面发现非键
在第 27 行/JSON 错误:JSON 文本未以数组或对象开头,并且未设置允许片段的选项。
运行 Xcode 构建...
Xcode 构建完成。 2.4s
无法构建 iOS 应用
Xcode 构建的错误输出:
↳
** 构建失败 **
Xcode 的输出:
↳
/Users/sirapol/Desktop/FirstCareFrontEnd/care_now_frontend_v1/build/ios/Debug-iphonesimulator/flutter_plugin_android_lifecycl
e/flutter_plugin_android_lifecycle.framework: 不允许资源分支、Finder 信息或类似的碎屑
命令 CodeSign 失败,退出代码非零
注意:使用新的构建系统
注:规划建设
注意:构建构建描述
警告:将架构 armv7 映射到 i386。确保此目标的架构和有效架构构建设置
已针对 iOS 模拟器平台正确配置。 (在项目 'Pods' 的目标 'image_picker' 中)
警告:将架构 arm64 映射到 x86_64。确保此目标的架构和有效架构构建设置
已针对 iOS 模拟器平台正确配置。 (在项目 'Pods' 的目标 'image_picker' 中)
warning: Capabilities for Signing & Capabilities 可能无法正常运行,因为它的权利使用占位符团队
ID。为解决此问题,select Runner 编辑器中的开发团队。 (在项目 'Runner' 的目标 'Runner' 中)`
这是我的 pubspec.yaml 文件的一部分
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
provider: ^3.0.0
http: ^0.12.0+4
image_picker: ^0.6.3+1
path_provider: ^1.1.0
dev_dependencies:
flutter_test:
sdk: flutter
这是我的 info.plist 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>care_now_frontend_v1</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<key>NSCameraUsageDescription</key>
<key>NSPhotoLibraryUsageDescription</key>
<key>NSMicrophoneUsageDescription</key>
<false/>
</dict>
</plist>
我不知道为什么会发生错误。因为我已经这样做过一次并且没有错误。感谢您的帮助
您需要确保在 plist 文件中的键值之后添加了一个值。在这些键下添加字符串值,应该可以解决问题。
示例:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow access to your phone's location</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow access your photo library</string>
<key>NSCameraUsageDescription</key>
<string>Allow access your phone's camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow the app to record using your phone's microphone</string>
至于架构映射错误,请尝试在 xcode 项目中将 iOS 部署目标设置为 9.0 或更高版本。
此外,我注意到您的代码示例中有一个尾随值,看起来应该将其移至下方
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
万一其他人有这个问题,如果你在文件末尾添加密钥,它将失败并发送 Xcode 无法读取 Info.plist 文件错误,测试它Xcode 版本 12。
例如这个文件可以正常工作:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
....
<key>NSPhotoLibraryUsageDescription</key>
<string>Share pictures</string>
<key>NSCameraUsageDescription</key>
<string>Share pictures</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
但是如果你像这样将键移到最后,它将失败:
....
<key>UIViewControllerBasedStatusBarAppearance</key>
<key>NSPhotoLibraryUsageDescription</key>
<string>Share pictures</string>
<key>NSCameraUsageDescription</key>
<string>Share pictures</string>
<false/>
</dict>
</plist>
我需要为我的应用程序使用 image_picker。我在我的 pubspec.yaml 文件中添加了 image_picker 依赖项,对于 iOS 我添加了 NSCameraUsageDescription NSPhotoLibrary使用说明 NS麦克风使用说明 到 info.plist 文件中,但在 iOS 模拟器上尝试 运行 应用程序时出现此错误。
这是我在尝试 运行 应用程序时遇到的错误。 `在调试模式下在 iPhone 11 Pro Max 上启动 lib/main.dart... /Users/sirapol/Desktop/FirstCareFrontEnd/care_now_frontend_v1/ios/Runner/Info.plist: 属性 列表错误:在里面发现非键 在第 27 行/JSON 错误:JSON 文本未以数组或对象开头,并且未设置允许片段的选项。 运行 Xcode 构建...
Xcode 构建完成。 2.4s 无法构建 iOS 应用 Xcode 构建的错误输出: ↳ ** 构建失败 **
Xcode 的输出: ↳ /Users/sirapol/Desktop/FirstCareFrontEnd/care_now_frontend_v1/build/ios/Debug-iphonesimulator/flutter_plugin_android_lifecycl e/flutter_plugin_android_lifecycle.framework: 不允许资源分支、Finder 信息或类似的碎屑 命令 CodeSign 失败,退出代码非零 注意:使用新的构建系统 注:规划建设 注意:构建构建描述 警告:将架构 armv7 映射到 i386。确保此目标的架构和有效架构构建设置 已针对 iOS 模拟器平台正确配置。 (在项目 'Pods' 的目标 'image_picker' 中) 警告:将架构 arm64 映射到 x86_64。确保此目标的架构和有效架构构建设置 已针对 iOS 模拟器平台正确配置。 (在项目 'Pods' 的目标 'image_picker' 中) warning: Capabilities for Signing & Capabilities 可能无法正常运行,因为它的权利使用占位符团队 ID。为解决此问题,select Runner 编辑器中的开发团队。 (在项目 'Runner' 的目标 'Runner' 中)`
这是我的 pubspec.yaml 文件的一部分
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
provider: ^3.0.0
http: ^0.12.0+4
image_picker: ^0.6.3+1
path_provider: ^1.1.0
dev_dependencies:
flutter_test:
sdk: flutter
这是我的 info.plist 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>care_now_frontend_v1</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<key>NSCameraUsageDescription</key>
<key>NSPhotoLibraryUsageDescription</key>
<key>NSMicrophoneUsageDescription</key>
<false/>
</dict>
</plist>
我不知道为什么会发生错误。因为我已经这样做过一次并且没有错误。感谢您的帮助
您需要确保在 plist 文件中的键值之后添加了一个值。在这些键下添加字符串值,应该可以解决问题。
示例:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow access to your phone's location</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow access your photo library</string>
<key>NSCameraUsageDescription</key>
<string>Allow access your phone's camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow the app to record using your phone's microphone</string>
至于架构映射错误,请尝试在 xcode 项目中将 iOS 部署目标设置为 9.0 或更高版本。
此外,我注意到您的代码示例中有一个尾随值,看起来应该将其移至下方
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
万一其他人有这个问题,如果你在文件末尾添加密钥,它将失败并发送 Xcode 无法读取 Info.plist 文件错误,测试它Xcode 版本 12。
例如这个文件可以正常工作:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
....
<key>NSPhotoLibraryUsageDescription</key>
<string>Share pictures</string>
<key>NSCameraUsageDescription</key>
<string>Share pictures</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
但是如果你像这样将键移到最后,它将失败:
....
<key>UIViewControllerBasedStatusBarAppearance</key>
<key>NSPhotoLibraryUsageDescription</key>
<string>Share pictures</string>
<key>NSCameraUsageDescription</key>
<string>Share pictures</string>
<false/>
</dict>
</plist>