Xcode编译打包Flutter项目问题总结

梦想与她 提交于 2021-01-24 10:35:41

一、编译运行过程遇到问题

1、控制台输出的报错信息中发现会有某些方法不存在,没有该命名的参数,或者是某些变量、参数不存在。

解决方法:在Flutter项目中pubspec.yaml将出现问题的插件的版本号切换为指定版本,即去掉 ^ 符号,因为有些插件用最新的可能会出现不兼容的问题,同时确保Flutter版本与开发项目时所用的版本一致。

2、[VERBOSE-2:platform_view_layer.cc(20)] Trying to embed a platform view but the PrerollContext does not support embedding

解决方法:进入项目目录下的IOS中的Runner,修改Info.plist

<key>io.flutter.embedded_views_preview</key>
<true/>

3、linked and embedded framework ‘App.framework’ was built for iOS Simulator linked and embedded framework ‘Flutter.framework’ was built for iOS Simulator

解决方法:
a、修改targets => Build Setting=>Validate WorkspaceNO
b、删除App.frameworkFlutter.framework后重新编译运行

4、运行过程控制台报0x000000010f8854d5 -[JPushPlugin setup:result:] + 437 6 Runner 0x000000010f8错误

解决方法:在项目中注释掉JPush插件以及相关代码即可

5、warning: The iOS deployment target ‘IPHONEOS_DEPLOYMENT_TARGET’ is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99. (in target ‘flutter_local_notifications’ from project ‘Pods’)

解决方法:
a、进入项目目录下的IOS,修改底下的Podfile文件

post_install do |installer| 
	installer.pods_project.targets.each do |target| 
		target.build_configurations.each do |config| 
			if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 10.0 
				config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
			end 
		end
	end
end

b、上述方法有时候还不能完全解决,还需要在Xcode中进行修改,在左侧项目栏搜索8.0,将相关参数设置为10.0

6、The linked library ‘xxxx.a/Framework’ is missing one or more architectures required by this target: armv7.

解决方法:在Target=>Build Settings =>Excluded Architectures中添加以下代码

EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))

7、Unable to install “…” Domain: com.apple.dt.MobileDeviceErrorDomain Code

解决方法:重新配置证书,然后编译运行

二、打包过程遇到问题

1、ld: bitcode bundle could not be generated because …

解决方法:
a、修改targets => Build Setting =>Enable BitcodeNO
b、在终端中进入项目根目录,先后执行flutter cleanflutter build ios,接着就可重新打包

2、ERROR ITMS-90189: "Redundant Binary Upload. You’ve already uploaded a build with build number ‘1’ for…

解决方法:需要在targets => General => Identity 中修改对应的version以及Build,在原有基础上增加即可。

三、上架App Store遇到的问题

1、上架App Store时报错ERROR ITMS-90087: "Unsupported Architectures.The executable for …/Frameworks/Flutter.framework contains unsupported architectures ’[x86_64]’
解决方法:

targets =>Build Phases 中点击左上角加号 New Run Script Phase,在shell中添加(注意:第四行中Flutter.framework为报错信息里面的Flutter.framework)

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name 'Flutter.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read    "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTAB LE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
 
EXTRACTED_ARCHS=() 
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o       "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
 
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create   "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
 
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged"    "$FRAMEWORK_EXECUTABLE_PATH" 
done	

2、使用Application Loader将ipa上传至App Store后,邮箱返回报错信息

ITMS-90683: Missing Purpose String in Info.plist - Your app’s code references one or more APIs that access sensitive user data. The app’s Info.plist file should contain a NSContactsUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. Starting Spring 2019, all apps submitted to the App Store that access user data are required to include a purpose string. If you’re using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. You can contact the developer of the library or SDK and request they release a version of their code that doesn’t contain the APIs. Learn more (https://developer.apple.com/documentation/uikit/core_app/protecting_the_user_s_privacy).
ITMS-90683: Missing Purpose String in Info.plist - Your app’s code references one or more APIs that access sensitive user data. The app’s Info.plist file should contain a NSCalendarsUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. Starting Spring 2019, all apps submitted to the App Store that access user data are required to include a purpose string. If you’re using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. You can contact the developer of the library or SDK and request they release a version of their code that doesn’t contain the APIs. Learn more (https://developer.apple.com/documentation/uikit/core_app/protecting_the_user_s_privacy).


解决方法:进入项目目录下的ios => Runner,修改Info.plist,往里面增加键值对,报错信息需要什么就添加什么,全部添加也可以。

<key>NSAppleMusicUsageDescription</key>
<string>是否允许此app访问媒体资料库</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>是否允许此app访问蓝牙</string>
<key>NSCalendarsUsageDescription</key>
<string>是否允许此app访问日历</string>
<key>NSCameraUsageDescription</key>
<string>是否允许此app访问相机</string>
<key>NSContactsUsageDescription</key>
<string>是否允许此app访问通讯录</string>
<key>NSHealthShareUsageDescription</key>
<string>是否允许此app访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>是否允许此app访问健康更新 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>是否允许此app访问位置</string>
<key>NSLocationUsageDescription</key>
<string>是否允许此app访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>是否允许此app在使用期间访问位置</string>
<key>NSMicrophoneUsageDescription</key>
<string>是否允许此app访问麦克风</string>
<key>NSMotionUsageDescription</key>
<string>是否允许此app访问运动与健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>是否允许此app访问相册</string>
<key>NSRemindersUsageDescription</key>
<string>是否允许此app访问提醒事项</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>是否允许此app访问语音识别</string>

如有问题,欢迎一起交流讨论。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!