Create an index library

Index libraries are private library indexes, podspec files in particular. For example, our cocoapods/ Repos directory stores indexes to hundreds of thousands of common libraries, but does not store code for specific libraries. (Even so, installing Cocoapods is slow.) When we have pod install in a specific project, we will download the source code based on the code address in the. Podspec file.

Similarly, we need to create an index library to hold the indexes of all our private libraries.

You don’t need to do this if you are publicly publishing Cocoapods.

  • Create a remote git repository, address to https://github.com/xuzhenhao/ZHSpecs.git
  • Run pod repo add [index library name]ZHSpecs [git address]github.com/xuzhenhao/Z…

At this point, you should see the ZHSpecs folder in the Cocoapods/Repos directory, alongside the public index library Master.

Creating a private library

Template-based creation

Creating an index library can be quickly created from a template with the instruction pod lib create [project name]. Including the vast majority of online tutorials are operated in this way, but personal actual project development down to feel obvious defects, I recommend the next one.

  • Sudo gem install colored2

This can be skipped. There is an obvious flaw in the template-created Example project and Classes folder.

  • If you’ve already developed it and are just pulling the code out of a private library, it’s not a problem. Just copy the files to the Classes directory and sort them out. Then under Example, pod Install previews the effect.
  • If you’re like me, debugging and developing from zero, it’s hard. You can only develop in the Example project, and when pod Install is executed, you see the logical directory in the Example project (imagine if you were modifying the AFN in the main project). The new group, drag files, and Classes folders are not identical.

Xcode creates a private library project

  • Xcoce create a new normal project and configure the.gitignore file.
  • Create a. Podspec file. This can be created using the pod Spec Create name, or you can copy a. Podspec file from another library and modify the file name and contents. Be sure to put it in the project root directory, the same as.xcodeProj. In addition, you need to copy the LICENSE file to the root directory. Create a Sources folder in the subdirectory to store all of our code.
  • Configure. Podspec files. You can refer to the following configuration, divided into multiple sub-libraries.

Pod::Spec.new do |s|
  s.name             = 'HBTTools'
  s.version          = '0.0.1'
  s.summary          = 'Tool Private Library'1. Encapsulates common tool classes, including classification, database, encryption, hot update, prompt box, version update module DESC.type= >'MIT', :file => 'LICENSE' }
  s.author           = { 'cloud'= >'[email protected]' }
  s.source           = { :git => 'https://e.coding.net/kdk/HBTTools.git', :tag => s.version.to_s ,:submodules => true}

  s.ios.deployment_target = '8.2'
  s.source_files = 'HBTTools/Sources/HBTools.h'
  
  s.public_header_files = 'HBTTools/Sources/HBTools.h'
  s.frameworks = 'Foundation'
  s.dependency 'HBNetworking'

  s.subspec 'HBCategories' do |ss|
    ss.source_files = 'HBTTools/Sources/HBCategories/**/*.{h,m}'
  end

  s.subspec 'HBDataBase' do |ss|
    ss.source_files = 'HBTTools/Sources/HBDataBase/**/*.{h,m}'
    ss.dependency 'FMDB'
  end

  s.subspec 'HBHUD' do |ss|
    ss.source_files = 'HBTTools/Sources/HBHUD/**/*.{h,m}'
    ss.dependency 'MBProgressHUD'.'~ > 0.9.1'
  end

  s.subspec 'HBVersion' do |ss|
    ss.source_files = 'HBTTools/Sources/HBVersion/**/*.{h,m}'
    ss.dependency 'Mantle'
  end
  s.subspec 'HBLog' do |ss|
    ss.source_files = 'HBTTools/Sources/HBLog/**/*.{h,m}'
    ss.dependency 'Mantle'
    ss.dependency 'HBTTools/HBDataBase'
  end
end

Copy the code

The project created this way is no different from our normal development, you can create new files and run debugging directly in the project. We specify the source code in the PodSpec so that other files in the project, such as the appDelegate, will not be downloaded when pod Install is used.

Publish a private library

  1. Type the version number. After development, first modify s.sion in podSpec, which is the library version number. It is best to give the project the same version number. Git push tags

  2. Verify podSpec validity

  • Pod Lib Lint native validation (version number will not be verified)
  • Remote validation of POD Spec Lint (with correct version number typed)

Optional parameters: – sources=https://e.coding.net/kdk/ZHSpecs.git github.com/CocoaPods/S… –allow-warnings –use-libraries

Sources is followed by the address of the index library. If you rely on a framework like AFN, you need to tell it where to find it. ZHSpecs is our own index library, which you need to add if your current private library relies on your other private libraries. –allow-warning Ignore warnings

  1. Submit the index file to the index library

3.1 If private library pod repo push [index library name][index file to submit. Podspec]. As with Pod Lib Lint, optional arguments are added as needed.

3.2 If the library is public

  • The pod Trunk Register mailbox will receive a verification email, click on the prompt to return to the console
  • pod trunk push

Mining pit record

  1. When sharing with a third party, pod install will fail to be installed if the umeng library contains. A static library file. target has transitive dependencies that include static binaries. Solution: Add S.stiatic_framework = true to your podSpec file