“This is the second day of my participation in the First Challenge 2022, for more details: First Challenge 2022”.
preface
CocoaPods was introduced in the previous section:
The differences between CocoaPods public and private libraries
Make the Framework and upload it to the CocoaPods library
This article will focus on the production process and the recording process encountered some problems and solutions.
The production process
First of all, we should first understand the whole production process, so that we can quickly understand the overall process of production, so that we can have a clear step in the following production.
- Create a private source repository (skip this step if one already exists)
- Create private
Pod
warehouse - Add private library source files (add code, resources, packages, and so on)
- Modify the
.podSpec
file - validation
.podSpec
file - Commit code to the remote repository
- push
.podSpec
file
Create a private source repository
1. In the remote repository, create a source index library, PodSpecs. (Remote warehouse can choose Github, GitLab, code cloud)
2. Add the remote index library to the local source (terminal type)
/**
pod repo add [repoName] [source]
*/
pod repo add component https://github.com/component/specs.git
Copy the code
Create a private Pod repository
- In the remote repository, create a source code
pod
Library. Note ⚠️ : don’t worry about local associations here. - Select a directory and create a local directory
Pod
Library project.
/** pod lib create pod library name */ pod lib create RTCComponentCopy the code
After the command is executed, a series of questions are displayed on the command line.
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- https://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> yes
Which testing frameworks will you use? [ Quick / None ]
> none
Would you like to do view based testing? [ Yes / No ]
> no
Copy the code
After executing the command, a Workspace will be created for us, which contains two projects. RTCComponent is the running Demo Project of our Pod library. Pods is the code project for our development library.
Add private library source files
We can import our code files or framework in Pods/Development Pods/RTCComponent. This step is to place our code and resource files in the project. The imported files and resource directories need to be configured in the.podSpec file, which will not be explained here.
Modify the. PodSpec file
Pod: : Spec. New do | s | s.n ame = 'RTCComponent' s.v ersion = '0.1.0 from' s.s ummary = 'components' s.d. escription =' XXXXXXXXXXXXXXXXX ' s.homepage = 'http://xxxx/component' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' }. s.author = { 'xxxxxxxx' => '[email protected]' } s.source = { :git => 'http://xxxx/component/RTCComponent.git', To_s} # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' S.iso. Deployment_target = '9.0' {# 'RTCComponent' => {# 'RTCComponent' => ['RTCComponent/Assets/*.png'] #} # here is the path of the header file # s.public_header_files = 'Pod/Classes/**/*.h' # If the framework is imported S.frameworks = 'OpenAL', 'Accelerate' # .tbd) s.libraries = 'sqlite3', 'resolv', 'c++', 'z' # '~> 5.0.2' s.dependency 'TXLiteAVSDK_Professional', '~> 8.9.10382' s.dependency 'SwiftyBeaver', '~> 1.9.3' # Log s.dependency 'SwifterSwift/SwiftStdlib' S.pod_target_xcconfig = {'VALID_ARCHS' => 'x86_64 armv7 arm64', 'ENABLE_BITCODE' => 'NO' } # s.user_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' } endCopy the code
Please refer to CocoaPods official documentation for details
Validate. PodSpec files
CD to the directory. Perform the following operations:
/** Network validation */ pod spec lint /** local validation */ pod lib lintCopy the code
Common additional processing:
- For more information, please join after the command
--verbose
- Ignore warning, please add after command
--allow-warnings
- To use the local library, please add after command
--use-libraries
- Check all problems, please join after command
--no-clean
- Depend on private library, need to add source, please add after command
--sources=
(note: if you rely on the public library, also need to add the public library source: https://github.com/CocoaPods/Specs – namely sources = private library, https://github.com/CocoaPods/Specs).
Commit code to the remote repository
Push local POD library project submission to remote repository, Tag and publish. 1. Submit the file to the local warehouse and push the file
/** CD PodProject /** git commit -m "commit" */ git commit -m "commit" /** git branch -m branch */ git branch -m Main / * * git remote add origin git repository address * / git remote add origin https://github.com/XXXX.git / * * git push -u origin branch */ git push -u origin mainCopy the code
2. Post with a Tag
Git push origin [tagName] */ git push origin "0.0.1" / Git push origin --tags */ git push origin --tagsCopy the code
Push. PodSpec file
Check the local repo, if yes, go to the next step, if not, add again (pod repo add [name] [source git address]).
pod repo list
Copy the code
After checking the local repository, start pushing the. Podspec file in the created Pod library to the specified source repository. First, go to the podspec directory again and do the following:
/** 推送命令: pod repo push [repoName] [name].podspec */
pod repo push component RTCComponent.podspec
Copy the code
All the flow is done by this point; Verification is probably the most problematic part of the process. If it passes, the release will be fine, so if it doesn’t, the release won’t succeed.
At the end of the article, I will summarize the problems encountered in the production process one by one. (If there are other problems encountered, they will be updated here.)
Summary of problems (Error)
- Fault 1: Verification fails
** BUILD FAILED ** The following build commands failed: CompileSwift normal x86_64 CompileSwiftSources normal i386 com.apple.xcode.tools.swift.compiler CompileSwift normal i386 CompileSwift normal arm64 (4 failures) Testing with `xcodebuild`.Copy the code
Solution: Add it to your. Podspec file; Refer to the iOS instruction set architecture
s.pod_target_xcconfig = { 'VALID_ARCHS' => 'x86_64 armv7 arm64' }
Copy the code
- Fault 2: Pod Install reported an error when the component relied on a third-party library containing a framework or. A file
target has transitive dependencies that include statically linked binaries:
Copy the code
Solution: Add the following code to your Podfile;
pre_install do |installer| Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end
Copy the code
- Problem 3: Xcode setting ENABLE_BITCODE
You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)
Copy the code
Solution: Set ENABLE_BITCODE to NO under target
Reference Documents:
CocoaPods makes official documents
Increase your team’s overall productivity with CocoaPods private libraries
GitHub will replace terms like master with main