Background: Our project was previously componentized, with logins and personal centers and base network requests separated into one module, camera module, home module. The modules are all introduced into the Framework. This makes compiling faster, but it’s a bit of a hassle to debug, and people have been trying to make pod. Recently, a project will provide two SDKS for the partners, one is device access and the other is device control. The basic network request and some tool classes need to be extracted first for everyone to use, but the previous Framework also includes login, which is not required by SDK.
1. To solve the problem that there are too many login services in the network request Framework, I originally thought of making the module into a POD and dividing it into two subspecs: network request and login. The idea was good, but the implementation was terrible. The last step of pod verification was always wrong, and the prefixHeader was used in pod, so it was too difficult to decouple a subspec. Finally, I came up with a better solution: create a target in the original framework: Only the basic network request and utility classes are included, so it is still a piece of code, and the framework does not include our company’s own login business. Perfect!!!!!
2. The device is connected to different modules such as Bluetooth and wifi. Our idea is to create a POD with multiple subspecs in it, so that people can directly install the pod if they want to use one. Since you can’t expose the source code, you need to make the Framework first and then make the corresponding Framework support POD.
1. How do I make my existing components support Cocoapod? It can be roughly divided into the following steps:
- Create and set up a private Spec Repo.
- The project project files needed to create the Pod and have an accessible project version control address.
- Create the podSpec file corresponding to the Pod.
- Tests the availability of the configured PodSpec file locally.
- Submit the PodSpec to a private Spec Repo.
- Add the new Pod to your personal project’s Podfile and use it.
- Update and maintain podSpecs.
Create and set up a private Spec Repo.
The Spec repo is actually a remote Git repository that contains many spec files. Cocoapods will be cloned into the ~/. Cocoapods /repos directory when you use it. This is the official repo
We need to create such a warehouse by ourselves. If the company does not have such a warehouse before, we need to create a remote warehouse on Gitlab, and then copy the address and enter it in the command line:
# pod repo add [Private Repo Name] [GitHub HTTPS clone URL]
$ pod repo add WTSpecs https://coding.net/wtlucky/WTSpecs.git
Copy the code
After executing, go to ~/.cocoapods/repos to see the private library you just created
The project project files needed to create the Pod and have an accessible project version control address
This is THE LMFramework, which includes login, personal center, region switching, network request, etc. I plan to only make the part of network request into POD. I changed the folder structure and put the corresponding part in a folder. Since this is already in the gitLab on the Intranet, there is no need to rebuild the Git repository.
Create the podSpec file corresponding to the Pod
CD Go to the corresponding directory and run the command
pod spec create LMFramework
Copy the code
Then start editing podSpec, which is a Ruby file
Pod: : Spec. New do | Spec | Spec. The name = "LMFramework" Spec. Version = "is 1.0.4" Spec. The summary = "A short description of LMFramework." spec.homepage = "An accessible address, License = "MIT" spec.author = {"jeremylu" => "[email protected]"} spec.platform = :ios, "10.0" spec.source = {:git => "git address ", :tag => "#{spec.version}"} The path of the current directory is podspec / / * * * / * only traverse the current folder traverse the current folder and subfolders, s.s ource_files = 'NetworkFramework/Classes / *. {h, m}' / / rely on third-party libraries, multiple, Newline spec.dependency 'AFNetworking','3.2.0' // Best to write spec.frameworks = 'Foundation','UIKit' // framework spec.vendored_frameworks = included in the project 'LMFramework NetworkFramework / *. The framework configuration in / / buildingsetting supachai panitchpakdi od_target_xcconfig = {' ENABLE_BITCODE' = > 'NO'} endCopy the code
To set the subspec, run the pod lib lint command to verify that the podSpec file is valid
This step is more problematic, will report all kinds of errors. Xcode building type warning is allowed, but error is not allowed.pod lib lint --allow-warnings
This kind of mistake- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
Generally no detailed information can be usedpod lib lint --verbose
Let’s look at the details.
Tests the availability of the configured PodSpec file locally.
Create your own demo and set up your Podfile
source 'https://cdn.cocoapods.org/' source 'http://git.aqara.com/root/APP_aqara_home_iOS_podspec.git' platform :ios, '10.3' inhibit_all_warnings! Target 'LoginDemo' do / / path to the location of the podfile as current location, set the source file location pod 'LMFramework' : path = > '~ / LMFramework NetworkFramework' endCopy the code
Then pod install to check whether the code can be used. It was ok the first time I did it, but failed to import it later. It is also ok to directly proceed to the next step, which is mainly used for debugging the code.
Submit the PodSpec to a private Spec Repo.
The first thing to do is to commit all the changes, and then create a new tag and push it to the remote end. It then commits to the REPO with just one command
$pod Repo push WTSpecs PodTestLibrary. Podspec # Is preceded by the local repo name and followed by the PodSpec nameCopy the code
After completion of the component library is added to our private Spec Repo, can enter into the ~ /. Cocoapods/repos/WTSpecs directory to view
At this point, our component library is complete.
Add the new Pod to your personal project’s Podfile and use it.
Here is a more detailed introduction
Update and maintain podSpecs.
Each time you want to release a version, you need to submit the code, tag it, and execute the command
pod repo push WTSpecs PodTestLibrary.podspec
Copy the code
Problems encountered
How does the Framework support POD?
Podspec sets the corresponding framework address
s.vendored_frameworks = 'XRGcSDKPods/Classes/*.framework' s.user_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' } # Settings do not support bitcodeCopy the code
build failure
Ld … /Build/Intermediates.noindex/App.build/Release-iphonesimulator/App.build/Objects-normal/arm64/Binary/App normal arm64
See link 5 for the answer.
FrameworkA depends on FrameworkB, how to connect?
Check both places for reasons shown here
Update:
Problem 1: You encountered this error while validating podSpec files.
pod lib lint TestSDK.podspec –allow-warnings –use-libraries
Pod ‘LMCameraFramework’, :path => ‘.. /APPCameraFramework’ pod install failed to find library A
Solution: Add library A’s Podsepc repo address to your podfile.
Reference links:
-
How does the Framework upload cocoaPod
-
Create a private PodSpec using Cocoapods
-
The grammar of the podfile
-
The framework can build multiple targets: simplified and standard versions
-
Podspec validation failed