项目场景:
flutter集成到原有ios项目上,将项目打包生成ipa文件,在通过爱思助手或者分发服务器分发安装。
解决方案:
1,在flutter module项目路径下,通过以下命令打包,其中–no-codesign表示不使用证书签名,后续会在打包ios项目的时候一起签名。若没有加上,则必须打开该flutter项目配置开发者账号的team和bundle ID,
flutter build ios --release --no-codesign
2,flutter module打包成功后,用xcode打开与其混编的ios项目,保证已经配置好开发者账号的team和bundle ID后,选择product下的Archive进行ios打包,打包中有可能出现以下错误:
../../flutter_module/.ios/Flutter/flutter_export_environment.sh: line 8: inherited: command not found========================================================================ERROR: Unknown FLUTTER_BUILD_MODE: distribution.Valid values are 'Debug', 'Profile', or 'Release' (case insensitive).This is controlled by the FLUTTER_BUILD_MODE environment variable.If that is not set, the CONFIGURATION environment variable is used.You can fix this by either adding an appropriately named buildconfiguration, or adding an appropriate value for FLUTTER_BUILD_MODE to the.xcconfig file for the current build configuration (Distribution).
根据上面提示的路径找到对应的flutter_export_environment.sh文件和Generated.xcconfig文件,打开添加以下代码:
//在export "FLUTTER_BUILD_DIR=build"这行下添加以下代码export "FLUTTER_BUILD_MODE=release"
添加完后再次执行Archive打包ios项目。
3,打包成功后会有如下图的弹窗:
此时选择右边Distribute App
根据需求选择发布的类型,选择好点击下一步
默认下一步,
此时该给打包好的项目添加证书签名了。在打包ios项目时,已经登录并设置好了开发者账号的team和bundle ID,此时只需选择第一项即可,xcode的会自动帮你创建证书,按提示一步步操作即可。
4,签名成功后,会有提示Export导出生成IPA文件,选择导出到指定路径即可。生成的IPA文件可以上传到分发服务器或者通过爱思助手安装到iphone上了。