Flutter iOS运行报错

Flutter IOS 编译步骤

一:准备环境

1、Mac 或者 mac虚拟机

虚拟机安装参考:点击链接

2、安装Flutter SDK

执行命令flutter doctor查看环境

3、安装Xcode

macOS Flutter环境 配置成功

二:修改配置文件

主要有两个文件的配置需要修改

1、Generated.xcconfig

ios/Flutter/下的Generated.xcconfig文件里,所涉及的到路径,必须要改成mac对于的路径。

// This is a generated file; do not edit or check into version control.FLUTTER_ROOT=/Users/metre/Desktop/workspace/flutterFLUTTER_APPLICATION_PATH=/Users/metre/Desktop/workspace/projects/[项目名称]FLUTTER_TARGET=/Users/metre/Desktop/workspace/projects/[项目名称]/lib/main.dartFLUTTER_BUILD_DIR=buildSYMROOT=${SOURCE_ROOT}/../build/iosFLUTTER_FRAMEWORK_DIR=/Users/metre/Desktop/workspace/flutter/bin/cache/artifacts/engine/iosFLUTTER_BUILD_NAME=1.0.0FLUTTER_BUILD_NUMBER=1

2、.packages

项目根目录下的.packages文件,里面的路径也要改成mac下路径。

三:使用xcode打开项目

Runner.xcworkspace

注意:不是选择Runner.xcodeproj打开,而是Runner.xcworkspace,否则编译会出错。

选择 [项目名称]/ios/Runner.xcworkspace打开,选择菜单Product—>Build

build

第一次build失败后,在[项目名称]/ios/下会生成一个Podfile文件 。

Podfile

如果没有生成,可以在该目录下手动创建一个Podfile文件,内容如下:

# Uncomment this line to define a global platform for your projectplatform:ios,'10.3'# CocoaPods analytics sends network stats synchronously affecting flutter build latency.ENV['COCOAPODS_DISABLE_STATS']='true'project'Runner',{'Debug'=>:debug,'Profile'=>:release,'Release'=>:release,}defparse_KV_file(file,separator='=')file_abs_path=File.expand_path(file)if!File.exists?file_abs_pathreturn[];endpods_ary=[]skip_line_start_symbols=["#","/"]File.foreach(file_abs_path){|line|nextifskip_line_start_symbols.any?{|symbol|line=~/^\s*#{symbol}/}plugin=line.split(pattern=separator)ifplugin.length==2podname=plugin[0].strip()path=plugin[1].strip()podpath=File.expand_path("#{path}",file_abs_path)pods_ary.push({:name=>podname,:path=>podpath});elseputs"Invalid plugin specification:#{line}"end}returnpods_aryendtarget'Runner'do# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock# referring to absolute paths on developers' machines.system('rm -rf .symlinks')system('mkdir -p .symlinks/plugins')# Flutter Podsgenerated_xcode_build_settings=parse_KV_file('./Flutter/Generated.xcconfig')ifgenerated_xcode_build_settings.empty?puts"Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."endgenerated_xcode_build_settings.map{|p|ifp[:name]=='FLUTTER_FRAMEWORK_DIR'symlink=File.join('.symlinks','flutter')File.symlink(File.dirname(p[:path]),symlink)pod'Flutter',:path=>File.join(symlink,File.basename(p[:path]))end}# Plugin Podsplugin_pods=parse_KV_file('../.flutter-plugins')plugin_pods.map{|p|symlink=File.join('.symlinks','plugins',p[:name])File.symlink(p[:path],symlink)pod p[:name],:path=>File.join(symlink,'ios')}endpost_installdo|installer|installer.pods_project.targets.eachdo|target|target.build_configurations.eachdo|config|config.build_settings['ENABLE_BITCODE']='NO'endendend

四:使用<终端>命令工具,build项目

image.png

先cd到项目的根目录下,执行命令flutter packages get下载第三方库。

然后cd 到 ios 目录下,再通过命令pod install安装第三方库。

build

如果正常,会如上图所示。

最后再回到Xcode上去编译。

全部完成配置后,xcode的完整目录接口应该如下图所示:

完整的目录结构

再编译 Product—>Build,就成功了

编译成功

五:可能遇到的问题

1、编译问题: script phase “[CP] Embed Pods Frameworks”

Framework重复

:-1: Multiple commands produce '/Users/GenlotRD/Library/Developer/Xcode/DerivedData/Runner-ahulhxjyhsnwsxgyjageaweqzpvb/Build/Products/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework':1) Target 'Runner' has copy command from '/Users/GenlotRD/IOS/vlt-channel-app/ios/Flutter/Flutter.framework' to '/Users/GenlotRD/Library/Developer/Xcode/DerivedData/Runner-ahulhxjyhsnwsxgyjageaweqzpvb/Build/Products/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework'2) That command depends on command in Target 'Runner': script phase “[CP] Embed Pods Frameworks”

解决办法:去掉 Flutter.framework

去掉 Flutter.framework 的勾

2、真机Release包白屏问题:

解决办法:先去项目根目录,运用以下命令,再使用xcode打包:

flutter cleanflutter build ios --release

3、错误:ios/Flutter/flutter_assets: No such file or directory

error:/Users/xxx/Downloads/projectName/ios/Flutter/flutter_assets:No such file or directory

解决办法:

由于现在使用的flutter版本生成的flutter_assets是放到App.framework里的,把flutter_assets从App.framework里拷贝出来放到Flutter文件夹里就可以了。

4、错误: CDN: trunk URL couldn't be downloaded

little:ios RD$ pod installAnalyzing dependencies[!]CDN:trunk Repo update failed-40error(s):CDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.6.0/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.6.2/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.6.3/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.7.0/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.8.3/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.8.4/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.8.4.1/JPush.podspec.json Response:Timeout was reachedCDN:trunk URL couldn'tbedownloaded:https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/b/0/d/JPush/1.8.5/JPush.podspec.json Response:Timeout was reached

编辑Podfile文件

vi Podfile

头部加上:

source 'https://cdn.cocoapods.org/'

5、错误:Building for iOS, but the linked and embedded framework

Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator.

6、错误:[!]CDN:trunk Repo update failed

source 'https://github.com/CocoaPods/Specs.git'

7、NO pod install

项目目录  cd ios pod install

解决方案:

https://flutter.dev/docs/development/ios-project-migration


转自链接:https://www.jianshu.com/p/8e402987fffd

你可能感兴趣的:(Flutter iOS运行报错)