XCode新增兩個工程聯動
接受了一箇舊專案,SDK中含有Pods,由於有一個新功能,需要在SDK中進行新增更改,但是SDK中含有Pods,因此不能簡單的將SDK新增到工程中去。具體的做法見下方,待我一一講來:
1、首先終端建立一個資料夾test
2、在資料夾中終端建立一個Podfile檔案,同時將原先的兩個含有Pods的工程拷貝進去。
Podfile檔案內容為:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! workspace 'JYAPP_IOS' xcodeproj 'DanaleSDK1/DanaleSDK.xcodeproj' xcodeproj 'HuaweiVideo/HuaweiVideo.xcodeproj' target 'HuaweiVideo' do xcodeproj 'HuaweiVideo/HuaweiVideo.xcodeproj' pod 'AFNetworking', '~> 3.1.0' pod 'AliyunOSSiOS', '~> 2.6.2' pod 'Masonry', '1.1.0' pod 'Reachability', '3.2' pod 'Braintree/UnionPay' pod 'Braintree/PayPal' pod 'OAStackView' pod 'FMDB' pod 'libqrencode', '~> 3.4.2' pod 'Bugly' pod 'TPKeyboardAvoiding' pod 'ReactiveCocoa', '2.3.1' pod 'TTTAttributedLabel' pod 'IQKeyboardManager' pod 'ZJAnimationPopView' pod 'MJExtension' pod 'FDFullscreenPopGesture' end target 'DanaleSDK' do xcodeproj 'DanaleSDK1/DanaleSDK.xcodeproj' pod 'AFNetworking', '~> 3.1.0' pod 'AliyunOSSiOS', '~> 2.6.2' pod 'Masonry', '1.1.0' pod 'Reachability', '3.2' pod 'Braintree/UnionPay' pod 'Braintree/PayPal' pod 'OAStackView' pod 'WechatOpenSDK' end
此時的檔案構成為:
3、分別進入DanaleSDK與HuaweiVideo資料夾,執行 $ rm -rf xxxxx.xcworkspace,將各自的xcworkspace檔案移除,然後刪除其中的pod相關檔案
4、然後在test中,執行pod install,執行成功後CocoaPods會報警告,
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `DanaleSDK` to `../Pods/Target Support Files/Pods-DanaleSDK/Pods-DanaleSDK.debug.xcconfig` or include the `../Pods/Target Support Files/Pods-DanaleSDK/Pods-DanaleSDK.debug.xcconfig` in your build configuration (`DanaleSDK/Pods/Target Support Files/Pods-DanaleSDK/Pods-DanaleSDK.debug.xcconfig`).
此時開啟JYAPP_IOS檔案,顯示為下圖
5、編譯任意一個工程
此時會報錯,
diff: /Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
原因為原先有Pods的配置檔案未刪除掉,還是預設使用以前的,因此此時需要將原先的配置檔案刪除,重新pod install
6、再次執行pod install後,編譯任意工程
還是編譯報錯,
error: /Applications/Xcode9.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-DanaleSDK
error: /Applications/Xcode9.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-DanaleSDK is not an object file (not allowed in a library)
原因為執行編譯時,未找到Pods-DanaleSDK,那麼此時需要去找此檔案。
此檔案報紅色,紅色為不存在此檔案,也可以看Pods---》Products中的
那麼此檔案應該怎麼生成呢?
7、開啟Scheme,如下圖
將對應的libPods-DanaleSDK.a與libPods-HuaweiVideo.a調出,編譯。
此時再次檢視第6步中截圖的檔案,不再是紅色。編譯任意一個工程檔案,OK,編譯通過。
以上就是Pods管理以前含有Pods的多個工程的步驟。
附:在A工程中如何引入SDK原始碼,一般做法為,開啟工程,然後將sdk原始碼拷貝到工程目錄下面,執行addFile新增到A目標工程中,然後將A工程中的.a庫刪除,再Build Phases中開啟Link Binary With Libraries中新增SDK原始碼對應的.a庫即可。最後找到A中引用的SDK的方法,cmd+左鍵,是否能夠跳轉,至此完結。