Xcode編譯打包Flutter項目問題總結

一、編譯運行過程遇到問題

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>

如有問題,歡迎一起交流討論。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章