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


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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 207,113评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,644评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 153,340评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,449评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,445评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,166评论 1 284
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,442评论 3 401
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,105评论 0 261
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,601评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,066评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,161评论 1 334
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,792评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,351评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,352评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,584评论 1 261
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,618评论 2 355
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,916评论 2 344

推荐阅读更多精彩内容