CocoaPods|CocoaPods 私有库

名词
私有库名字
私有库地址
私有repo 名字
私有repo 地址
1、创建pod模板
pod lib create 私有库名字

What platform do you want to use?? [ iOS / macOS ] > iOSWhat language do you want to use?? [ Swift / ObjC ] > ObjCWould you like to include a demo application with your library? [ Yes / No ] > YesWhich testing frameworks will you use? [ Specta / Kiwi / None ] > NoneWould you like to do view based testing? [ Yes / No ] > NoWhat is your class prefix? > CC

【CocoaPods|CocoaPods 私有库】随后会开始创建项目,项目路径如下
. ├── Example --demo位置 │├── Podfile │├── Podfile.lock │├── Pods │├── Tests │├── podDemo │├── podDemo.xcodeproj │└── podDemo.xcworkspace ├── LICENSE ├── README.md ├── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj ├── podDemo │├── Assets --资源位置(xib、mp3) │└── Classes --源代码位置 └── podDemo.podspec10 directories, 5 files

2、将此仓库关联远端仓库 我们这面关联的是gitlab
git remote add origin 私有库地址

3、修改podSpec文件
Pod::Spec.new do |s| s.name= 'CCWechat' s.version= '0.1.0' s.summary= 'A short description of CCWechat.' - 初始化后必须修改 s.description= <<-DESC - 初始化后必须修改 TODO: Add long description of the pod here. DESC s.homepage= '私有库地址'- 初始化后必须修改 s.license= { :type => 'MIT', :file => 'LICENSE' } s.author= { '彭盛凇' => '个人邮箱' }- 初始化后必须修改 s.source= { :git => '私有库地址', :tag => s.version.to_s }- 初始化后必须修改 s.ios.deployment_target = '9.3'- 初始化后必须修改 s.source_files = 'CCWechat/Classes/**/*' #s.xcconfig = { #'VALID_ARCHS' =>'arm64 x86_64', #} 不支持i386时开启 #s.resources = 'CCActiveNotification/Assets/**/*' 资源 s.dependency 'JPush', '3.1.2' s.dependency 'QQ_XGPush', '3.3.3-beta' s.dependency 'CCActiveNotification', '0.1.1' end

4、本地验证
基础命令
pod lib lint 私有库名字.podspec

如果创建的私有库中的依赖库包含.a静态库时,在基础命令后拼接
--use-libraries --allow-warnings

如果要打印详细信息,在基础命令后拼接
--verbose

如果创建的私有库中引用到其他私有库时,在基础命令后拼接
--sources=私有repo地址,https://github.com/CocoaPods/Specs.git

eg:
pod lib lint 私有库名字.podspec--sources=私有repo地址,https://github.com/CocoaPods/Specs.git --use-libraries --allow-warnings --verbose

可选
pengchengsongdeMacBook-Pro:~ pengchengsong$ pod lib lint --help Usage:$ pod lib lintValidates the Pod using the files in the working directory.Options:--quickLint skips checks that would require to download and build the spec --allow-warningsLint validates even if warnings are present --subspec=NAMELint validates only the given subspec --no-subspecsLint skips validation of subspecs --no-cleanLint leaves the build directory intact for inspection --fail-fastLint stops on the first failing platform or subspec --use-librariesLint uses static libraries to install the spec --sources=https://github.com/artsy/Specs,masterThe sources from which to pull dependent pods (defaults to https://github.com/CocoaPods/Specs.git). Multiple sources must be comma-delimited. --privateLint skips checks that apply only to public specs --swift-version=VERSIONThe SWIFT_VERSION that should be used to lint the spec. This takes precedence over a .swift-version file. --skip-import-validationLint skips validating that the pod can be imported --skip-testsLint skips building and running tests during validation --silentShow nothing --verboseShow more debugging information --no-ansiShow output without ANSI codes --helpShow help banner of specified command

5、将本地pod相关所有文件推送到远端,并打上对应的tag
6、推送至指定私有repo
基础命令
pod repo push 私有repo名字 私有库名字.podspec

如果创建的私有库中的依赖库包含.a静态库时,在基础命令后拼接
--use-libraries --allow-warnings

如果要打印详细信息,在基础命令后拼接
--verbose

eg:
pod repo push 私有repo名字 私有库名字.podspec --sources=私有repo地址,https://github.com/CocoaPods/Specs.git --use-libraries --allow-warnings

可选
pengchengsongdeMacBook-Pro:~ pengshengsong$ pod repo push --help Usage:$ pod repo push REPO [NAME.podspec]Validates `NAME.podspec` or `*.podspec` in the current working dir, creates a directory and version folder for the pod in the local copy of `REPO` (~/.cocoapods/repos/[REPO]), copies the podspec file into the version directory, and finally it pushes `REPO` to its remote.Options:--allow-warningsAllows pushing even if there are warnings --use-librariesLinter uses static libraries to install the spec --sources=https://github.com/artsy/Specs,masterThe sources from which to pull dependent pods (defaults to all available repos). Multiple sources must be comma-delimited. --local-onlyDoes not perform the step of pushing REPO to its remote --no-privateLint includes checks that apply only to public repos --skip-import-validationLint skips validating that the pod can be imported --skip-testsLint skips building and running tests during validation --commit-message="Fix bug in pod"Add custom commit message. Opens default editor if no commit message is specified. --use-jsonPush JSON spec to repo --swift-version=VERSIONThe SWIFT_VERSION that should be used when linting the spec. This takes precedence over a .swift-version file. --no-overwriteDisallow pushing that would overwrite an existing spec. --silentShow nothing --verboseShow more debugging information --no-ansiShow output without ANSI codes --helpShow help banner of specified command

7、更新repo
pod repo update 私有repo名字

8、search SDK
pod search 私有库名字

更新私有库 1、执行上述第4、5、6、7、8步即可
其他相关命令 1、移除私有repo(当私有库需要clean的时候)
pod repo remove 私有repo名字

2、添加私有repo(当私有库需要clean的时候)
pod repo add repoName 私有repo地址

3、删除searchIndex(当search 不到的时候使用)
rm -rf ~/Library/Caches/CocoaPods/search_index.json

4、子库概念
s.subspec 'Component_sub' do |aa| aa.source_files = 'Component/Classes/Component_sub/**/*' #aa.dependency 'AFNetworking', '~> 3.2.0' end

遇到的问题 1、依赖库中架构不支持i386
相关错误
ld: warning: ignoring file /var/folders/r2/qz19lm3s15lf5x9ltjgjq1x80000gn/T/CocoaPods-Lint-20190417-8094-1gelzu0-CCPush/Pods/JPush/libjpush-ios-3.1.2.a, missing required architecture i386 in file /var/folders/r2/qz19lm3s15lf5x9ltjgjq1x80000gn/T/CocoaPods-Lint-20190417-8094-1gelzu0-CCPush/Pods/JPush/libjpush-ios-3.1.2.a (4 slices) ld: warning: ignoring file /var/folders/r2/qz19lm3s15lf5x9ltjgjq1x80000gn/T/CocoaPods-Lint-20190417-8094-1gelzu0-CCPush/Pods/JCore/libjcore-ios-1.2.6.a, missing required architecture i386 in file /var/folders/r2/qz19lm3s15lf5x9ltjgjq1x80000gn/T/CocoaPods-Lint-20190417-8094-1gelzu0-CCPush/Pods/JCore/libjcore-ios-1.2.6.a (4 slices) Undefined symbols for architecture i386: "_kJPFServiceErrorNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_kJPFNetworkIsConnectingNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_kJPFNetworkFailedRegisterNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_kJPFNetworkDidSetupNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_kJPFNetworkDidRegisterNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_kJPFNetworkDidLoginNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) -[CCPush cc_jPushNetworkDidLogin:] in libCCPush.a(CCPush.o) "_kJPFNetworkDidCloseNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_OBJC_CLASS_$_JPUSHRegisterEntity", referenced from: objc-class-ref in libCCPush.a(CCPush.o) "_kJPFNetworkDidReceiveMessageNotification", referenced from: -[CCPush initJPProviderWith:] in libCCPush.a(CCPush.o) "_OBJC_CLASS_$_JPUSHService", referenced from: objc-class-ref in libCCPush.a(CCPush.o) ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

在podspec文件中加上下方配置即可
s.xcconfig = { 'VALID_ARCHS' =>'arm64 x86_64', }

参考链接:
https://www.jianshu.com/p/2bba5e7bc7fe
https://stackoverflow.com/questions/41594895/pod-trunk-push-fail-when-build-xcodebuild-in-i386/41614762#41614762
end

    推荐阅读