Flutter打包iOS IPA失败:多环境配置下系列问题求助
遇到的错误及对应解决步骤
错误1:Flutter找不到Release类配置
The Xcode project defines build configurations: Debug-prod, Debug-uat, Debug-dev, Release-dev, Profile-dev, Profile-uat, Profile-prod, Release-uat, Release-prod
Flutter expects a build configuration named Release or similar.
Open Xcode to fix the problem:
open ios/Runner.xcworkspace
- Click on "Runner" in the project navigator.
- Ensure the Runner PROJECT is selected, not the Runner TARGET.
- Click the Editor->Add Configuration->Duplicate "Release" Configuration.
解决办法:
- 更高效的方式是直接指定环境打包,不用额外创建默认Release配置,避免后续资源路径冲突:
执行打包命令时带上--flavor参数指定环境,搭配版本信息参数,例如打包prod环境:flutter build ipa --flavor prod --release --build-name=1.0.0 --build-number=1 - 如果坚持要创建默认Release配置,按提示在Xcode操作后,必须确保该配置的图标、plist等资源路径都指向正确的文件。
错误2:找不到AppIcon.appiconset/Contents.json
Oops; flutter has exited unexpectedly: "PathNotFoundException: Cannot open file, path = 'ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json' (OS Error: No such file or directory, errno = 2)".
你已经为每个环境配置了对应图标,问题出在环境配置未关联正确的图标资源:
解决办法:
- 打开
ios/Runner.xcworkspace,选中左侧导航栏的Runner项目(注意是Project,不是Target) - 切换到「Info」标签,找到「Configurations」区域,为每个环境的Release/Profile/Debug配置指定对应的Assets Catalog:
比如Release-prod配置,要选择你为prod环境创建的Assets-prod.xcassets,而非默认的Assets.xcassets - 检查每个环境的图标目录下是否存在
Contents.json,如果缺失,从其他正常的图标目录复制一份,修改里面的图标文件名与当前环境的图标对应即可 - 打包时必须带上
--flavor参数,让Flutter加载对应环境的配置
错误3:GoogleService-Info.plist路径错误
Looking for GoogleService-Info.plist in /Users/alijaber/Desktop/PhazeRo/Saar-parent-github/saar_mobile_parent/ios/config/default/GoogleService-Info.plist
No GoogleService-Info.plist found. Please ensure it's in the proper directory.
解决办法:
- 把三个环境的
GoogleService-Info.plist分别放到对应目录,比如ios/config/dev/、ios/config/stag/、ios/config/prod/ - 在Xcode中选中Runner Target,切换到「Build Phases」标签,展开「Copy Bundle Resources」,移除里面的
GoogleService-Info.plist(避免多环境冲突) - 切换到「Build Settings」标签,搜索「User-Defined」,添加变量
GOOGLE_SERVICE_INFO_PLIST,并为每个环境设置对应路径:- dev环境:
$(SRCROOT)/config/dev/GoogleService-Info.plist - stag环境:
$(SRCROOT)/config/stag/GoogleService-Info.plist - prod环境:
$(SRCROOT)/config/prod/GoogleService-Info.plist
- dev环境:
- 回到「Build Phases」,点击「+」添加「New Run Script Phase」,脚本内容填写:
这样打包时会自动复制对应环境的plist到正确位置cp "${GOOGLE_SERVICE_INFO_PLIST}" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist" - 打包时记得带上
--flavor参数,比如:flutter build ipa --flavor prod --release
内容的提问来源于stack exchange,提问作者Ali

