接手的公司iOS項(xiàng)目是組件化開發(fā),項(xiàng)目也比較大疾牲,App Store顯示的包有400多M,并且無法適配模擬器衙解。所以阳柔,首先我來進(jìn)行模擬器適配。
1蚓峦、報(bào)錯(cuò)building for iOS Simulator, but linking in object file built for iOS
如報(bào)錯(cuò)
In /Users/zhanyu/Workspace/iOS/********_iOS/Pods/ZYMapKit/BaiduMapFramework/BaiduMapAPI_Utils.framework/BaiduMapAPI_Utils(BMKOpenPoiOption.o), building for iOS Simulator, but linking in object file built for iOS, file
'/Users/zhanyu/Workspace/iOS/********_iOS/Pods/ZYMapKit/BaiduMapFramework/BaiduMapAPI_Utils.framework/BaiduMapAPI_Utils' for architecture arm64
這個(gè)問題目前應(yīng)該只出現(xiàn)在M1芯片的Mac上舌剂,似乎又是一個(gè)兼容性問題,因?yàn)镸1芯片的Mac本身就是arm架構(gòu)暑椰,所以模擬器自然也支持arm架
第一步修改Podfile文件
# config.build_settings['VALID_ARCHS'] = ['arm64', 'x86_64','arm64-apple-ios']
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
第二步修改霍转,在編譯設(shè)置中,對(duì)模擬器排除 arm64
然后pod install
再檢查
第三步:在主項(xiàng)目和pod項(xiàng)目的PROJECT的Build Settings中一汽,刪除VALID_ARCHS(整個(gè)刪除谴忧,不能只刪除value留下Key
Xcode 12不再支持VALID_ARCHS,需移除角虫!采用Excluded Architectures過濾掉不需要的架構(gòu)即可沾谓!
如果項(xiàng)目在Build Settings下的User-Defined中添加了VALID_ARCHS屬性,需要將其移除戳鹅,否則無法在Xcode 12編譯運(yùn)行設(shè)備均驶。
如果確實(shí)需要設(shè)定支持/不支持的架構(gòu),通過Excluded Architectures配置即可枫虏。
ps:ios模擬器運(yùn)行報(bào)錯(cuò)
Command PhaseScriptExecution failed with a nonzero exit code妇穴,也可以嘗試以上方式解決
2、模擬器不支持的庫瑞修德隶债、推送腾它、PKI、PLPlaykit死讹、愛心推PLMediaStreamingKit
如報(bào)錯(cuò)Could not find module 'RXD_SDK' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios, at:
先用如以下方式過濾import和調(diào)用代碼
#if targetEnvironment(simulator)
import RXD_SDK
#else
#endif
如報(bào)錯(cuò)
Undefined symbol: OBJC_CLASS$_HDtuiliuVideoViewController
在HDtuiliuVideoViewController類中找到代碼引用PLPlaykit代碼
#if TARGET_IPHONE_SIMULATOR
#else
// 初始化 PLPlayerOption 對(duì)象
PLPlayerOption *option = [PLPlayerOption defaultOption];
// 更改需要修改的 option 屬性鍵所對(duì)應(yīng)的值
[option setOptionValue:@10 forKey:PLPlayerOptionKeyTimeoutIntervalForMediaPackets];
[option setOptionValue:@2000 forKey:PLPlayerOptionKeyMaxL1BufferDuration];
[option setOptionValue:@1000 forKey:PLPlayerOptionKeyMaxL2BufferDuration];
[option setOptionValue:@(YES) forKey:PLPlayerOptionKeyVideoToolbox];
[option setOptionValue:@(kPLLogNone) forKey:PLPlayerOptionKeyLogLevel];
self.player = [PLPlayer playerLiveWithURL:[NSURL URLWithString:self.model.playUrl] option:option];
self.player.delegate = self;
self.player.playerView.frame = CGRectMake(0, 180, kScreenWidth, 250);
[self.videoView addSubview:self.player.playerView];
[self.player play];
#endif
如調(diào)用了PLMediaStreamingKit中代碼也報(bào)錯(cuò)瞒滴,可以修改
#if TARGET_IPHONE_SIMULATOR
#else
[PLStreamingEnv initEnv];
#endif
其他的地方,如
#if targetEnvironment(simulator)
#else
if viewController is QYSessionViewController {
printLog(message: "已進(jìn)入客服頁面")
#endif
#if targetEnvironment(simulator)
#else
let option = QYSDKOption.init()
option.appKey = ThirdLibConfig.shared.QY_NIM_Appkey
option.appName = ""
option.isFusion = false
QYSDK.shared().register(with: option)
#endif
/** 獲取Wifi Ssid */
public func getSsid() -> String? {
if let interface : CFArray = CNCopySupportedInterfaces() {
#if targetEnvironment(simulator)
#else
NSLog("\(interface)");
for i in 0..<CFArrayGetCount(interface) {
let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interface, i);
NSLog("\(interfaceName)");
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
if let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString), let interfaceData = unsafeInterfaceData as? [String : AnyObject] {
if let ssid = interfaceData["SSID"] as? String {
return ssid
}
}
}
}
#endif
return nil;
}
3、七牛 - Qiniu (= 7.2.5)版本中HappyDNS問題
dyld[52532]: Library not loaded: @rpath/HappyDNS.framework/HappyDNS
Reason: tried: '/Users/zhanyu/Library/Developer/Xcode/DerivedData/***-fjmngiqwdvbcdyasnbmgeutgqouy/Build/Products/Debug-iphonesimulator/HappyDNS.framework/HappyDNS' (errno=2), '/Users/zhanyu/Library/Developer/CoreSimulator/Devices/CFD4C541-F60A-4190-8CEB-4CFC402A7431/data/Containers/Bundle/Application/3C0A8B63-C41B-49CA-8073-960CF74711ED/*****.app/Frameworks/HappyDNS.framework/HappyDNS' (fat file, but missing compatible architecture (have 'armv7,arm64', need 'x86_64')),
PLShortVideoKit在podspec中dependency了Qiniu7.2.5妓忍,Qiniu7.2.5有個(gè)0.3版本HappyDNS.framework依賴虏两,但是這個(gè)版本壓根沒用還會(huì)導(dǎo)致報(bào)錯(cuò)。
這個(gè)問題我想了很多方式解決都沒用世剖,
如果升級(jí)PLShortVideoKit到3.2.5定罢,七牛變成8.2.0,會(huì)導(dǎo)致其他報(bào)錯(cuò)旁瘫。
如果刪除HappyDNS.framework的引用 -framework "HappyDNS"祖凫,模擬器能跑起來,但是pod install后酬凳,刪除的內(nèi)容又會(huì)復(fù)原惠况。
最終方法:
在本地引入PLShortVideoKit.podspec,版本還是3.1.1粱年,但不依賴s.dependency 'Qiniu', '7.2.5'
在本地引入Qiniu.podspec售滤,版本還是7.2.5罚拟,但不依賴s.dependency 'HappyDNS', '~> 0.3'
然后再Podfile中
# PLShortVideoKit用自己編寫的podspec台诗,剔除HappyDNS,解決HappyDNS不適配模擬器問題
pod 'PLShortVideoKit', :podspec => 'PLShortVideoKit.podspec'
pod 'Qiniu', :podspec => 'Qiniu.podspec'
pod install后完美解決問題
模擬器能跑起來了
打包時(shí)爆了個(gè)錯(cuò)
error: Build input file cannot be found: '/Users/zhanyu/Library/Developer/Xcode/DerivedData/***-bilorlkikiiqdgbzqzutxjdoxkfz/Build/Intermediates.noindex/ArchiveIntermediates/JFDriver/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/JFDriverWidgetExtension.appex/***WidgetExtension'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target '***WidgetExtension' from project 'JFDriver')
在***WidgetExtension target 以下地方release也要進(jìn)行設(shè)置
如果一個(gè).framework只有真機(jī)庫赐俗,需要在模擬器中運(yùn)行拉队,此時(shí)加載庫的時(shí)候會(huì)報(bào)錯(cuò)。
解決方法:在Excluded Source File Names中配置
只有在模擬器環(huán)境下阻逮,不使用的庫:(如果在代碼中還要加上#if TARGET_OS_SIMULATOR進(jìn)行模擬器的邏輯判斷粱快。)