

构建Potatso问题集锦及解决方案
source link: https://www.tlanyan.me/build-potatso-problems-and-solutions/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

转载请注明文章出处: https://tlanyan.me/build-potatso-problems-and-solutions/
前言
半年前写过一篇构建自用Potatso的教程“ 构建自己的iOS网络代理客户端 ”。当时除libYAML依赖下载不正常外,编译测试使用全过程都很顺利。文章投递到几个平台被数万网友围观,不少网友根据教程在构建时遇到各种问题。最初我以为是网友看教程不仔细或构建环境差异造成,没多注意。后来陆续有网友加我QQ,让我怀疑写完文章后代码有了重大更新。
终于在昨天(除夕)抽出时间,用最新版的代码构建Potatso并安装到我最新版iOS系统的iPad上。这个过程花费了几个小时,覆盖了许多网友咨询我的问题,本文中将一一给出解决方案。
如果你的 Xcode版本是9.4.1 ,使用 commitID为318a5e1 的代码,根据“ 构建自己的iOS网络代理客户端 ”中的教程可以顺利的编译和安装Potatso到 iOS12系统以下的设备 。如果你的设备升级到了最新版,或者遇到其他问题,请继续阅读本文。
为什么执着于自建客户端?由于iOS生态的封闭性,正常情况下只能通过App Store下载应用。应用下架后,可能会导致手机重置、买新手机后无法安装客户端。而安卓、Windows、MacOS则不会有这个问题,只要安装文件存在,总是有的用。自己构建的客户端永不会下架,放心可靠。
构建步骤
这节简要回顾构建Potatso的流程:
1. 安装Cocospods
如果已安装,请略过此步。
- 更新系统的gem版本:打开终端,输入:
sudo gem update --system
; - 设置国内gem源:
gem sources --list
输出为https://gems.ruby-china.org/
请略过此步;否则先删除官方源再添加gems国内源:gem sources --remove https://rubygems.org/; gem sources --add https://gems.ruby-china.org/
; - 安装Cocospods:
sudo gem install cocoapods
。
2. 构建Potatso
构建Potatso的步骤如下:
- 克隆代码:
git clone https://github.com/haxpor/Potatso.git
; - 更新子模块:
cd Potatso; git submodule update --init
; - 安装依赖:打开
Podfile
,将第一行改成:source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
(使用清华的CocoaPods源),然后运行pod install --verbose
; - 使用XCode打开
Potatso.xcworkspace
; - 更改
Potatso
及PacketTunnel
、TodayWidget
两个子项目的Bundle ID
,例如本人分别改成:potatso.tlanyan.me
、potatso.tlanyan.me.PacketTunnel
和potatso.tlanyan.me.TodayWidget
; - 更改
Potatso
及PacketTunnel
、TodayWidget
两个子项目Capabilities
中的App Group
和Keychain Sharing
的Group:在”App Groups”中删除原有的group.io.wasin.potatso
,新增自己的group,例如:”group.potatso.tlanyan.me”;在”Keychain Sharing”中输入自己的group ID; - 打开”PotatsoBase/Potatso.m”文件,将
shareGroupIdentifier
函数的返回值改成自己的group id; - 将iPhone等iOS设备连接到电脑,目标选择新接入的设备,点击左上角的“build and run”按钮,Xcode会编译并安装App到设备上,然后启动。
可能遇到的问题
昨天几个小时的折腾,遇到的十来个问题。下文将一一列出,并给出解决方案。构建过程中你可能会遇到不止一个错误,请根据错误信息按 Ctrl + F
在本文中查找。如果遇到其他新的问题,欢迎留言或加Q群688196496。
1. the sandbox is not in sync with the Podfile.lock. Run ‘pod install’ or update your CocosPods installation.
问题截图:
原因:pod依赖未安装
解决办法:安装依赖,执行命令: pod install --verbose
2. Diff:/Podfile.lock: No such file or directory
使用新版代码并安装好依赖后,这应该是构建过程中最先出现的问题。
问题截图:
原因:根据错误描述跟踪脚本执行流程,发现是执行预构建脚本时 SRCROOT
环境变量的值无法获取(或被错误置为空)导致。
解决方案: 尝试过更改构建时生成的临时脚本文件、注入全局环境变量等,这些方法均不凑效。后来通过 diff
发现脚本由文件 Potatso.xcodeproj/project.pbxproj
文件中的配置生成,该文件在 pod install
后被修改。解决办法很简单:还原更改。执行完 pod install
命令后,执行 git checkout Potatso.xcodeproj/project.pbxproj
,问题解决。
3. No podspec found for CallbackURLKit
in ./Library/CallbackURLKit
问题截图:
原因:子模块的代码未下载
解决方案:初始化子模块代码,执行命令: git submodule update --init
4. The operation couldn’t be completed. Unable to log in with account ‘xxxx’. The login details for account ‘xxxx’ / No profiles for ‘xxxx’ were found: Xcode couldn’t find any iOS App Development provisioning profiles matching ‘xxx’ / Code signing is required for product type…
问题截图:
原因:Apple ID过期未续费
解决方案:Apple ID续费或换其他可用的ID
5. No account for team ‘xxx’. Add a new account in the Accounts preference pane or verify that your accounts have valid…
错误信息基本与上一条相同,只是账号换成了team ID。
问题截图:
原因:team ID不在已添加的账号内
解决方案:在属性页面的 Team
中选择自己的账号
6. Your account does not have sufficient permissions to modify containers. / No profiles for ‘xxxx’ were found
问题截图:
原因:该Bundle ID已经被其他Apple ID使用
解决方案:换一个新的
7. An Application Group with Identifier ‘xxxx’ is not available. Please enter a different string.
问题截图:
原因:Group ID已经被其他Apple ID使用
解决方案:用一个新的
8. Module ‘Crashlytics’ not found
这个错误未截图。
原因:Podfile文件里没有加这个库
解决方案:打开Podfile,在 def library
中添加一行: pod 'Crashlytics', '~> 3.10.7'
,然后执行 pod install --verbose
。
备注:该解决方案参考Github的issue: https://github.com/haxpor/Potatso/issues/117 。注意pod安装依赖后,会更改 Potatso.xcodeproj/project.pbxproj
文件,直接编译会出现第二个问题。正确操作应当如下:先备份 Potatso.xcodeproj/project.pbxproj
文件,然后执行 pod install --verbose
,成功后将文件覆盖。后续出现pod依赖更新的情况也应该按此步骤操作。
9. Could not locate device support files
问题截图:
原因:Xcode版本过低,不支持iOS 12.1系统。根据官方页面,需要Xcode 10
解决方案:安装Xcode 10,文件较大,根据网速需要一定时间,请耐心等待
10. Invalid redeclaration of ‘<-‘ EnumOprators.swift
问题截图:
原因: ObjectMapper
的版本过低
解决办法:使用新版的 ObjectMapper
:打开 Podfile
,将 ObjectMapper
那一行改成 pod 'AlamofireObjectMapper', '~> 5.0'
备注:解决方案参考 https://stackoverflow.com/questions/53038918/xcode-10-update-issue-with-alamofire-objectmapper
11. Type ‘RLMIterator ‘ does not conform to protocol ‘Sequence’
问题截图:
原因:这个问题不清楚具体原因。怀疑是 Realm
这个库的问题,没有实现 Sequence
接口。我将 RealmSwift
改到最新的3.7.6问题亦没有解决。不懂Swift,不过感觉是 RMLIterator
或者Proxy/RuleSet等存在问题。
解决办法:注销 PotatsoMode/DBUtils.swift
中的相关代码,具体是174-190和202-218行之间的代码。
备注:解决方案来自: https://github.com/haxpor/Potatso/issues/109 。所有错误中,只有这个错误不是完美解决。
12. Initializer for conditional binding must have Optional type, not ‘[Rule]’
问题截图:
原因:非nil值不应该使用 if let
(我自己的理解,毕竟不懂Swift)
解决办法:将 Potatso/Core/API.swift
第65和256行的 if
和大括号去掉,65行修改示意:
// 修改前 // if let parsedObject = Mapper<Rule>().mapArray(JSONArray: rulesJSON as! [[String : Any]]){ // let parsedObject = Mapper<Rule>().mapArray(JSONArray: rulesJSON as! [[String : Any]]) // rules.append(contentsOf: parsedObject) //} // 修改后 let parsedObject = Mapper<Rule>().mapArray(JSONArray: rulesJSON as! [[String : Any]]) rules.append(contentsOf: parsedObject)
备注:解决办法的灵感来自: https://stackoverflow.com/questions/31038759/conditional-binding-if-let-error-initializer-for-conditional-binding-must-hav 。当然这个问题和Potatso无关。
还有一个错误截图:
具体什么忘了。如果你遇到了或者有解决方案,可留言告诉我。
参考
Recommend
-
111
白鹭H5游戏转微信小游戏问题集锦,你关心的都在这里 发表于2018-01-04 评论3
-
182
以区块链(以太坊)为主攻方向,兼顾drools等其他Java技术,分享技术文章,为中国的技术发展做出贡献
-
71
总结—Harbor问题集锦
-
55
-
51
本文为 AI 研习社编译的技术博客,原标题 : Data Science and Machine Learning Interview Questions 作者 | George...
-
63
-
62
README.md iOS Potatso源码(配置下自己的开发证书就能编译版本),对你有帮助的话欢迎star 本着开源的精神。希望大家不要用做其他目的。得知有人想要发布到到app...
-
72
全文共 2564 字,预计学习时长 5 分钟
-
70
常见Spring Boot面试问题集锦,死角一个不留! 本文将讨论Spring Boot中最常见的10个面试问题。在当今就业市场中,这些问题出现的频率呈上升趋势并且有一些棘手。 ...
-
61
我写的一篇文章,希望对spring初学者有所帮助: 1、如何学习Spring? 你可以通过下列途径学习spring: ①. spring下载包中doc目录下的MVC-step-by-step和sample目录下的例子都是比较好的spring开发的例子。
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK