Cocoapods Application Part 2-private database-related, cocoapods Part 2

Source: Internet
Author: User
Tags install cocoapods

Cocoapods Application Part 2-private database-related, cocoapods Part 2
This is related to the second part of the first part see http://blog.csdn.net/yohunl/article/details/47982949 or http://www.cocoachina.com/ios/20150906/13323.html
Here, we use the first part to describe the framework project created using pod lib create YohunlUtilsPod. the creation process will not be repeated here, of course, you can also download the demo https://github.com/yohunl/YohunlUtilsPod I have created
PS: since it is a private library, we basically won't use github. I believe everyone in the company has a corresponding git platform. No matter which git platform is used, the operations are the same.

I. Build your own private spec RepositoryOpen the hidden directory and run the terminal command defaults write com. apple. finder AppleShowAllFiles-bool TRUE; killall Finder (disable the hidden terminal command defaults delete com. apple. finder AppleShowAllFiles; killall Finder) to open the hidden directory. cocoapods (this directory is in your personal directory, for example,/Users/yohunl/on my computer /. cocoapods)
Please note that ,. the folder repos under cocoapods. The repo here is the abbreviation of the repository. repos stores a collection of warehouses. here, the master is the official repository of cocoapods, which is stored in the specs directory of our so-called public database. It is a collection of podspec files submitted to the open-source library of cocoapods. its structure is as follows:
The composition method is specName -- version -- specName. podspec (specName is used in the master database. podspec. json. the json file is a podspec file with a suffix. As for why the official library does this, I have no reason. commands can be usedpod ipc specTo convert the spec file to json .)
Of course, you may be wondering how this folder comes from. This folder is the first time you install cocoapods after you install cococoapods, cocoapods is self-built by running the pod setup command (this pod setup command does not require manual execution ). however, if you want to recreate the official repos repository set, you can execute the pod repo remove masterpod setup command to recreate the pod repo folder.

It's official reference to building a private repo document http://guides.cocoapods.org/making/private-cocoapods.html.
We create an empty repository on github named yohunlSpecs, which stores the specs files of all our own private libraries, just as the official https://github.com/CocoaPods/Specs is used to store all official specs files
Creating a local Private repos official reference Private http://guides.cocoapods.org/making/private-cocoapods.html Private Pods writes are very detailed and examples are given$ pod repo add REPO_NAME SOURCE_URLThe REPO_NAME is the name of the private repo to be added, followed by its address. Note that this is only creation, that is, it is only in ~ The/. cocoapods/repos directory contains a folder, but the spec file is not added to it.
Run the command pod repo add yohunlSpecs git@github.com on the terminal: yohunl/yohunlSpecs. git or pod repo add yohunlSpecs https://github.com/yohunl/yohunlSpecs.git, many articles said, it is best to use the http mode git address here, but I tried, both are OK, after the command is executed in. under the cocoapods directory
No. Here is a private repository named yohunlSpecs, Which is empty.
2. Add the project we created in tutorial 1YohunlUtilsPodTo the yohunlSpec library created above (PS: Since this yohunlUtilsPod was created using pod lib create, it has already created the podspec file. of course, if your project has been established, you can use the command pod spec create specName to create, the official create spec file documentation Documentation, you can refer to the http://www.cocoachina.com/ios/20150228/11206.html ). open the spec file of the project
Modify the corresponding items as needed. this file is essentially a ruby file. after modification, run pod spec lint or pod lib lint to verify that the spec is qualified.
Enter the project directory and run the pod spec lint command. You will get [!] 2 out of 2 specs failed validation. This error is strange. Don't worry about it! Other errors cannot be ignored. Modify them as prompted until no other errors exist! Use the command pod lib lint to verify that it is correct.

The https://guides.cocoapods.org/terminal/commands.html#commands pod command looks at the difference between the two commands pod spec lint-used to verify the podspec file added locally using the pod spec create (however, this command usually appears 2 out of 2 specs failed validation. we recommend that you use pod lib lint. The pod lib lint checks the validity of the spec of the lib project created by pod lib create (tested, this command also applies to the first case .)
After Command verification, our YohunlUtilsPod. podspec complies with the specifications. since the repo of cocoapods is based on the git tag, we need to add a tag to the project YohunlUtilsPod. note: The tag added here must be the same as the one described in the podspec file. Otherwise, cocoapods will not know what code to download when others reference it. add a tag to the project. You can use a third-party tool or a command line (xcode does not support tag settings ).,Here I use tower, a tool that I am familiar.You can also use a familiar tool or command line. If you use the command line, $ git tag '1. 000000' $ git push -- tags $ git push origin master

Create a tag 1.0.0 (consistent with the description in the podspec file) and push it to github. Go to github. You can see that the tag has been added successfully. Here we will derive it. Here it is generally similar to version 1.0.2. The version number of the specification reference http://semver.org/lang/zh-CN/ we later build the project version number is best in line with the specification!

Run the command pod repo push yohunlSpecs YohunlUtilsPod. podspec [in the directory where YohunlUtilsPod. podspec is located]

After the execution is complete, we can see that. cocoapods has changed.

We can see that our podspec file has been added to the yohunlSpecs repo and has been set up according to the format.

Run pod search YohunlUtilsPod
We can see that it has been created.
Iii. Test availabilityCreate a common project named TestPodFrameworkDemo and add the podfile file to the directory, add pod 'yohunlutilspod '$ pod init create podfile file Modify file podfile content to target 'testpodframeworkdemo' dopod 'yohunlutilspod' end
Target 'testpodframeworkdemotests' do
End
Run $ pod install
At this time, get a prompt
Nima !!!! It's not scientific. The name of pod search is: why is it not executed ???? What is the situation ???? In fact, if you do not specify it, the pod install will only search for it under the master, and our spec file is under yohunlSpecs, of course, it cannot be found!

Solution: add source 'https: // github.com/yohunl/yohunlSpecs.git' at the top of the podfile file. # address of our own private spec repository source 'https: // github.com/CocoaPods/Specs.git' # address of the official repository
By default, if you do not add source, the system will use https://github.com/cocoapods/specs.git by default. However, when you export source, the system will no longer automatically search for the official source, so both sentences must be added !!!!!For example, if your file contains the source 'https: // your source' https: // github.com/CocoaPods/Specs.git', otherwise, other official-based pods cannot be used. For example: platform: ios, '7. 0 'target 'networklibtest' dopod 'networklib 'pod 'sdwebimag' # pod 'networklib',: path => '.. /NetworkLib '# pod 'networklib',: path => '~ /Code/Cocoapods/podTest/PodTestLibrary 'endtarget' networklibtesttests' doend
If the message does not contain source 'https: // github.com/cocoapods/specs.git', you will see lingyohunldembp:networklibtest yohunl $ pod install
Updating local specs repositories
Cloning spec repo 'yohunl' from 'https: // github.com/yohunl/NetworkLibSpec.git'
Analyzing dependencies [!] Unable to find a specification for 'sdwebimage'
Run pod install again.

In the future, if you want to use this private library, you need to add source 'https: // your 'yohunlutilspod 'to the podfile file'


Digress:

1. How can I check the number of local repos?The command pod repo can be used to know the local repo !!SZ-lingdaiping: TestPodFrameworkDemo yohunl $ pod repo

Master
-Type: git (master)
-URL: https://github.com/CocoaPods/Specs.git
-Path:/Users/yohunl/. cocoapods/repos/master

1. The repo just shows that it not only lists the total number of local repo, but also the address of each repo.

2. There are many podspec under a repo, for example, there are hundreds of thousands under the master, so how can we verify that they all comply with the specifications?For example, we can use commands to enter~ /. Cocoapods/repos/Under yohunlPodSpecsThe executed pod repo lint. (There is a point) is to verify all/Users/yohunl/. cococoapods/repos/yohunl under this repo
SZ-lingdaiping: yohunl $ pod repo lint.

Linting spec repo 'yohunl'

.

Analyzed 1 podspecs files.

All the specs passed validation.


3. Common cocoapods commandsPod list lists all available third-party libraries pod search query searches third-party libraries that contain queries Note: These two commands only exist locally/Users/yohunl /. if you search for files under cocoapods/, you can update the local pod repo to update the master first, search for pod lib create frameworkName and create a framework project pod lib lint to verify whether a podspec file has an error podinstall -- no-repo-update error. Here, the parameter-no-repo-update, yes. Tell cocoapods not to update repo. does it feel that every pod install is slow, because every time the local repo is updated, and this parameter is added, the process is skipped, soon pod init will be able to create an empty podfile to create pod spec file pod spec create spec name http://www.theonlylars.com/blog/2013/01/20/cocoapods-creating-a-pod-spec/pod installCommands may cause many operations. To learn more about the command execution details, add--verbose


4. other methods to use the framework we have createdAfter we add source 'https: // uninstall install
Go to the. cocoapods folder and you will see another repo: yohunl !!! What problems does this mean? This shows me What pod repo add yohunlSpecs git@github.com: yohunl/yohunlSpecs. gitpod repo push yohunlSpecs YohunlUtilsPod. podspec these two sentences just to add spec file to https://github.com/yohunl/yohunlSpecs. after the repo is added, we can delete the repo added to the local device.
Delete the repo command pod repo remove yohunlSpecs [pod repo remove repo name]




We deleted the private library we added. [Haha, you actually have hidden directories. You can also directly go in and delete folders!] Pod repo remove yohunlpod repo remove yohunlSpecs
After deletion, you can see


Run the pod install command to find that the system automatically runs


If you do not add repos (that is, do not add the podspec file to the. cocopods folder of the system), can you use cocoapods? It is also possible to target 'testpodframeworkdemo' dopod 'yohunlutilspod ',: path =>'/Users/yohunl/YohunlUtilsPod 'end
Target 'testpodframeworkdemotests' do
End
After downloading a code containing the podspec file, if you want to use it, you can directly specify the path through the path of the pod (previously you can also use: local, but now it has been: path replaced ).. note in the cocopods Folder: the path after path is the path of the directory where the podspec file is located. It is also possible to execute pod install.
But in this way, cocoapods will be placed in the Development Pods folder.
This method is also possible. You do not need to add podspec to a private repository # source 'https: // github.com/yohunl/yohunlspecs.git'your source 'https: // github.com/CocoaPods/Specs.git'
Target 'testpodframeworkdemo' do # pod 'yohunlutilspod ',: path =>'/Users/yohunl/YohunlUtilsPod 'pod 'yohunlutilspod ',: git => 'https: // your
Target 'testpodframeworkdemotests' do
End
You can also use the following method # pod 'yohunlutilspod ': path =>'/Users/yohunl/YohunlUtilsPod '# You can # pod 'yohunlutilspod',: git => 'https: // github.com/yohunl/YohunlUtilsPod.git' # You can # pod 'yohunlutilspod ',: podspec =>'/Users/yohunl/YohunlUtilsPod. podspec '# specifies the podspec file, which can be # pod 'yohunlutilspod',: podspec => 'https: // container # tested. This method does not work # pod 'yohunlutilspod ',: podspec => 'https: // github.com/yohunl/YohunlUtilsPod.git/YohunlUtilsPod/YohunlUtilsPod.podspec' # The test fails and the podspec file cannot be found.


If you are sure that your podspec file is correctly available, you can directly go to the https://github.com/yohunl/yohunlspecs podspecfile (of course, you must comply with the format requirements)


5. Third-party plug-in commands for packaging the frameworkCocoapods plug-in cocoapods-packager to package the class library. The advantage of installing the sudo gem install cocoapods-packager command is that, by renaming the referenced third-party library, this plug-in solves the class library naming conflict issue.



Reference document http://www.cnblogs.com/brycezhang/p/4117180.html develop and package static library http://www.iwangke.me/2013/04/18/advanced-cocoapods/#jtss-tsina with CocoaPods
Http://www.iwangke.me/2013/04/18/advanced-cocoapods/
Http://eric-gao.iteye.com/blog/2128283 submits framework to cocoapods official go to http://www.cocoachina.com/ios/20150508/11785.html to build private library
Http://blog.sigmapoint.pl/automatic-build-of-static-library-for-ios-for-many-architectures/
Some of the three articles are no longer applicable to the new versions of xcode and cocoapods with http://blog.sigmapoint.pl/developing-static-library-for-ios-with-cocoapods? Http://blog.sigmapoint.pl/avoiding-dependency-collisions-in-ios-static-library-managed-by-cocoapods/http://blog.sigmapoint.pl/automatic-build-of-static-library-for-ios-for-many-architectures/

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.