1、新建flutter項目,先在iOS真機上運行,然后在iOS模擬器上運行可能會報錯如下(或者先在模擬器上運行然后在真機上運行,報錯類似):
Error output from Xcode build:
?
** BUILD FAILED **
Xcode's output:
?
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
error: Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS. (in target 'Runner' from project 'Runner')
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.
解決辦法:flutter已經給出了方案
,各位看官如果不想看官網,我給大家翻譯一下:
用xcode 打開項目,找到App.framework 和 Flutter.framework刪掉,
然后在Build Phases 和Embed Frameworks 中分別查看 App.framework 和 Flutter.framework 是否還存在,確保這兩個地方也已經刪掉
然后在 Build Phases 中的 Thin Binary 添加如下兩條命令:
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" thin
接下來在Build Settings 中 Other Linker Flags 添加這個: $(inherited) -framework Flutter
再次運行項目,就可以了。
2、從GitHub上clone 其他人的項目,在模擬器上運行報錯:
[!] CDN: trunk Repo update failed - 4 error(s):
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/c/7/9/Reachability/3.0.0/Reachability.podspec.json Response: Couldn't connect to server
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/c/7/9/Reachability/3.1.0/Reachability.podspec.json Response: Couldn't connect to server
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/c/7/9/Reachability/3.1.1/Reachability.podspec.json Response: Couldn't connect to server
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/c/7/9/Reachability/3.2/Reachability.podspec.json Response: Couldn't connect to server
解決方法: 打開ios->podFile文件,在podFile 文件中添加 source 'https://github.com/CocoaPods/Specs.git',然后再次運行項目,就可以了。
3、Compiler message:
lib/commom/net/http_util.dart:288:21: Error: 'Key' is imported from both 'package:encrypt/encrypt.dart' and 'package:flutter/src/foundation/key.dart'.
final key = Key.fromUtf8(GWR1);
我引入了一個加密的第三方庫,這個庫里面包含一個類Key 和 系統的庫里面的Key 重名了,系統不知道該從哪個庫里面取。
解決辦法:給引用的第三方庫起個別名EncryptLib,使用第三方庫的時候在前面加上這個別名,重新編譯就好了
4、AndroidStudio 設備列表一直顯示loading狀態:
解決方案:
關閉AndroidStudio(不關閉的話好像不行),找到flutter的安裝目錄,進入bin/cache目錄,找到lockfile文件并且將這個文件刪除,終端重新執行flutter doctor,然后再打開AndroidStudio,就可以了。
5、fatal: unable to access 'https://chromium.googlesource.com/webm/libwebp/'解決方法
換了一個電腦環境,把項目clone到本地,運行iOS模擬器的時候一直卡在pod install,cd 到ios 目錄運行pod install,發現有個庫一直安裝失敗,
[!] Error installing libwebp
[!] /usr/local/bin/git clone https://chromium.googlesource.com/webm/libwebp /var/folders/cn/cg4r_mnn7h3fkznjlm7vqtxc0000gn/T/d20180820-45387-i7eiac --template= --single-branch --depth 1 --branch v1.0.0
Cloning into '/var/folders/cn/cg4r_mnn7h3fkznjlm7vqtxc0000gn/T/d20180820-45387-i7eiac'...
fatal: unable to access 'https://chromium.googlesource.com/webm/libwebp/': Failed to connect to chromium.googlesource.com port 443: Operation timed out
解決方案:前往cocospods 緩存庫文件目錄:~/.cocoapods/repos/edu-git-cocoapods-specs/Specs/1/9/2/libwebp,Mac電腦的版本不同,目錄可能稍有差別,反正就是找到libwebp的緩存地址,找到最新版本,1.2.0,將里面的配置文件git 地址換一下,在操作之前為了防止有誤,我copy了一個副本,把https://chromium.googlesource.com/webm/libwebp 替換為https://github.com/webmproject/libwebp.git 并保存
然后再執行pos install ,如果還是失敗,肯能是網絡問題,多執行幾次就可以了。
持續更新中...