一個flutter項目,其實也不是太老,主要是flutter升級的太快,新同事加載flutter項目時,總會遇到這樣那樣奇奇怪怪的問題,這里記錄一下,希望能幫到遇到同樣困難的其他同學。
1. 在ios目錄下,執行 pod install --clean-install 后,出現架包錯誤;
錯誤如下圖所示:
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "AgoraRtcEngine_iOS":
In snapshot (Podfile.lock):
AgoraRtcEngine_iOS (= 3.4.6)
In Podfile:
agora_rtc_engine (from `.symlinks/plugins/agora_rtc_engine/ios`) was resolved to 4.0.7, which depends on
AgoraRtcEngine_iOS (= 3.5.0.3)
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* changed the constraints of dependency `AgoraRtcEngine_iOS` inside your development pod `agora_rtc_engine`.
You should run `pod update AgoraRtcEngine_iOS` to apply changes you've made.
[!] Automatically assigning platform `iOS` with version `12.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `[https://guides.cocoapods.org/syntax/podfile.html#platform](https://guides.cocoapods.org/syntax/podfile.html#platform)`.
2.根據提示信息,輸入命令:pod install --repo-update
命令輸入后,依舊報錯,錯誤信息如下圖所示:
Updating local specs repositories
$ /usr/bin/git -C /Users/ioskaifa110/.cocoapods/repos/cocoapods fetch origin --progress
remote: Enumerating objects: 16015, done.
remote: Counting objects: 100% (6919/6919), done.
remote: Compressing objects: 100% (227/227), done.
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
error: 3334 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: index-pack failed
[!] CocoaPods was not able to update the `cocoapods` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
3.依舊報錯,根據提示輸入命令:pod repo update --verbose
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update
Updating spec repo `aliyun-aliyun-specs`
Updating spec repo `cocoapods`
$ /usr/bin/git -C /Users/ioskaifa110/.cocoapods/repos/cocoapods fetch origin --progress
fatal: unable to access '[https://github.com/CocoaPods/Specs.git/](https://github.com/CocoaPods/Specs.git/)': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
[!] CocoaPods was not able to update the `cocoapods` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:187:in `rescue in update_git_repo'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:178:in `update_git_repo'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-core-1.11.2/lib/cocoapods-core/source.rb:354:in `update'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:144:in `block (3 levels) in update'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/user_interface.rb:64:in `section'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:143:in `block (2 levels) in update'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:142:in `each'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:142:in `block in update'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:140:in `open'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/sources_manager.rb:140:in `update'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/command/repo/update.rb:23:in `run'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:52:in `run'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/gems/cocoapods-1.11.2/bin/pod:55:in `<top (required)>'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/bin/pod:23:in `load'
/usr/local/Cellar/cocoapods/1.11.2_1/libexec/bin/pod:23:in `<main>'
4.依舊報錯,根據提示,再來一次:pod repo update --verbose
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update
Updating spec repo `aliyun-aliyun-specs`
Updating spec repo `cocoapods`
$ /usr/bin/git -C /Users/ioskaifa110/.cocoapods/repos/cocoapods fetch origin --progress
remote: Enumerating objects: 16048, done.
remote: Counting objects: 100% (6974/6974), done.
remote: Compressing objects: 100% (199/199), done.
remote: Total 16048 (delta 6769), reused 6950 (delta 6762), pack-reused 9074 Receiving objects: 100% (16048/16048), 2.43 MiB | 3.54 MiB/s, done.
Resolving deltas: 100% (11033/11033), completed with 2320 local objects.
From [https://github.com/CocoaPods/Specs](https://github.com/CocoaPods/Specs)
bcfb480b2a7b..babb3cec1793 master -> origin/master
$ /usr/bin/git -C /Users/ioskaifa110/.cocoapods/repos/cocoapods rev-parse --abbrev-ref HEAD
master
$ /usr/bin/git -C /Users/ioskaifa110/.cocoapods/repos/cocoapods reset --hard origin/master
HEAD is now at babb3cec1793 [Add] AliInteractiveDocumentCore 1.5.0-rc8
Updating spec repo `trunk`
CDN: trunk Relative path downloaded: deprecated_podspecs.txt, save ETag: W/"61bc05f6-8987f"
CDN: trunk Going to update 13 files
CDN: trunk Relative path: all_pods_versions_1_1_7.txt, has ETag? W/"61bbfe1a-9b9"
CDN: trunk Relative path: all_pods_versions_5_d_c.txt, has ETag? W/"61bbfe1a-495"
CDN: trunk Relative path: all_pods_versions_1_d_9.txt, has ETag? W/"61bc040d-8a7"
CDN: trunk Relative path: all_pods_versions_e_9_d.txt, has ETag? W/"61bbfe1a-4d8"
CDN: trunk Relative path: all_pods_versions_b_2_d.txt, has ETag? W/"61b6ff40-57c"
CDN: trunk Relative path: all_pods_versions_1_6_1.txt, has ETag? W/"61bc040d-475"
CDN: trunk Relative path: all_pods_versions_3_7_4.txt, has ETag? W/"61bbfe1a-464"
CDN: trunk Relative path: all_pods_versions_6_f_0.txt, has ETag? W/"61bbfe1a-34a"
CDN: trunk Relative path: CocoaPods-version.yml, has ETag? "61b6ff40-38"
CDN: trunk Relative path: all_pods_versions_c_7_9.txt, has ETag? W/"61bbfe1a-50d"
CDN: trunk Relative path: all_pods_versions_3_7_9.txt, has ETag? W/"61b6ff40-417"
CDN: trunk Relative path: all_pods_versions_f_4_e.txt, has ETag? W/"61bc040d-4bb"
CDN: trunk Relative path: all_pods_versions_1_9_2.txt, has ETag? W/"61bc040d-1bb"
CDN: trunk Relative path downloaded: all_pods_versions_1_1_7.txt, save ETag: W/"61bc07cd-9b9"
CDN: trunk Relative path downloaded: all_pods_versions_1_d_9.txt, save ETag: W/"61bc05f5-8a7"
CDN: trunk Relative path downloaded: all_pods_versions_1_6_1.txt, save ETag: W/"61bc05f5-475"
CDN: trunk Relative path downloaded: all_pods_versions_e_9_d.txt, save ETag: W/"61bc05f5-4d8"
CDN: trunk Relative path downloaded: all_pods_versions_5_d_c.txt, save ETag: W/"61bc05f5-495"
CDN: trunk Relative path downloaded: all_pods_versions_f_4_e.txt, save ETag: W/"61bc05f5-4bb"
CDN: trunk Relative path downloaded: all_pods_versions_b_2_d.txt, save ETag: W/"61bc07cd-57c"
CDN: trunk Relative path downloaded: all_pods_versions_3_7_9.txt, save ETag: W/"61bc07cd-417"
CDN: trunk Relative path downloaded: all_pods_versions_3_7_4.txt, save ETag: W/"61bc05f5-464"
CDN: trunk Relative path downloaded: all_pods_versions_6_f_0.txt, save ETag: W/"61bc05f5-34a"
CDN: trunk Relative path downloaded: all_pods_versions_c_7_9.txt, save ETag: W/"61bc05f5-50d"
CDN: trunk Relative path downloaded: all_pods_versions_1_9_2.txt, save ETag: W/"61bc05f5-1bb"
CDN: trunk Relative path downloaded: CocoaPods-version.yml, save ETag: "61bc07cd-38"
備注:LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443,出現這個錯誤,一般是網絡不好導致 git 連接失敗,一般情況下,多更新幾次就好了,需要一點點耐心。
5.OK,這次沒有報錯信息了,去xcode里面看看;
在AndroidStudio選擇ios目錄,點擊右鍵,選擇Xcode打開,在Xcode下確認以下幾項:
1).簽名確定沒有錯誤,這個非常重要!
target -》signing & capabilities
如果有錯,去project -》info -》 configuration 把錯誤的版本刪除再添加,可解決簽名錯誤問題;必須先刪除再添加,直接修改可能不起作用。
備注:對于ios端開發來說,簽名是否正確非常重要,多個版本的簽名,如果有一個版本的簽名錯了,可能導致一些不可預知的錯誤。
舉個我同事的例子吧。
同一個項目,添加一個插件,我這邊是成功的,他那邊各種錯誤,初始化都不能成功,怎么樣都解決不了。經過xcode配置對比發現,他的release版本的簽名是報錯的,把簽名重新設置后,插件也可以正常使用了。
2).確定沒有包含不必要的配置
target ->build phases->link binary with Libraries下查看,有沒有不使用的framework,如果有就去掉;
6. 項目被更新后,再次執行:pod install --clean-install
報錯信息如下所示:
Analyzing dependencies
[!] Unable to find a specification for `AlicloudPush (~> 1.9.9)` depended upon by `rammus`
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
[!] Automatically assigning platform `iOS` with version `12.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `[https://guides.cocoapods.org/syntax/podfile.html#platform](https://guides.cocoapods.org/syntax/podfile.html#platform)`.
ioskaifa110@ioskaifadeiMac ios % pod install --repo-update
Updating local specs repositories
Analyzing dependencies
[!] Unable to find a specification for `AlicloudPush (~> 1.9.9)` depended upon by `rammus`
You have either:
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
[!] Automatically assigning platform `iOS` with version `12.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `[https://guides.cocoapods.org/syntax/podfile.html#platform](https://guides.cocoapods.org/syntax/podfile.html#platform)`.
7.根據6的提示,去修改Podfile文件,在頭部添加:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/aliyun/aliyun-specs.git'
備注:這項目使用了阿里云的移動推送,在Podfile配置中,需要加入這兩個資源。
8.繼續執行 pod install --clean-install
BMKLocationKit.release.xcconfig:1:1: unable to open file (in target "BMKLocationKit" in project "Pods")
上面的命令各自執行來了一遍,錯誤解決。
9.啟動報錯
?
** BUILD FAILED **
Xcode's output:
?
error: the following command failed with exit code 0 but produced no further output
CompileC /Users/ioskaifa110/....../ios/build/Pods.build/Debug-iphoneos/flutter_local_notifications.build/Objects-normal/arm64/FlutterLocalNotificationsPlugin.o /Users/ioskaifa110/Downloads/flutter/.pub-cache/hosted/pub.flutter-io.cn/flutter_local_notifications-8.1.1+1/ios/Classes/FlutterLocalNotificationsPlugin.m normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'flutter_local_notifications' from project 'Pods')
/Users/ioskaifa110/Downloads/flutter/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-2.0.13/ios/Classes/FlutterWebView.m:395:23: warning: 'requiresUserActionForMediaPlayback' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
configuration.requiresUserActionForMediaPlayback = true;
10.執行5.2,項目中有使用地圖,是否缺少地圖插件;
排除結果,少了一個系統庫文件;
11.報錯:Build input file cannot be found: '/Users/ioskaifa110/.../ios/plugins/mobpush/MobpushPlugin.m'
無用的插件沒刪除干凈,到指定目錄下刪除;
12.報錯:/Users/ioskaifa110/rsdun_flutter_app/ios/build/Pods.build/Release-iphoneos/SwiftyGif.build/module.modulemap:9:12: Header 'SwiftyGif-Swift.h' not found
解決辦法:http://www.lxweimin.com/p/00991deee746,不可以;
http://www.lxweimin.com/p/0f6600a0cc67,不可以;
13.清除緩存:product -》clean
解決不了,那就試試清除緩存吧,在AndroidStudio開發中,經常使用這一招廢棄緩存信息。
14.錯誤:Module 'agora_rtc_engine' not found
問題解決解決著,又回到了原點,相關命令在執行一遍。
flutter build iOS (flutter clean ,flutter pub get) 多次后,問題解決;
15.支付寶某個庫文件找不到,使用xcode導入,問題解決。
在對接移動推送時,案例中曾寫了一句話,請正確導入配置文件。剛開始我忽略了這句話,配置文件拷貝一下不就OK了嗎?(當然,我也是ios開發小白,最近才踏進一只腳)
事實卻不是這樣的,必須使用Xcode的導入功能,xcode才能找到和識別配置文件,拷貝進去是找不到的,這或許和xcode的開發機制有關系吧!這可是我用大量時間換來的寶貴經驗,特別適合小白。
最后總結
項目運行不起來,當然很著急,看到密密麻麻的報錯信息,也很頭疼。但是仔細研究了這些錯誤之后,發現解決這些錯誤并不費力,而且有規律可循,那就是根據英文的提示進行解決,有提示命令的運行提示命令即可,這些就可以解決百分之八十的錯誤了。