background
Using binary components requires the business side to install plug-ins
There are many business parties, and the demand for binary is uneven. It is not very intrusive to install plug-ins, which is not conducive to the free use of business parties.
Binary packaging ignores the source files and dependencies of a subspec
Ignore the subspec packaging, which is cumbersome to add one by one, but can be automated.
To solve
You do not need to install the CocoapoDS-IMy-bin plug-in
- Modify the plugin to rename the file that generates the bin private library and remove the binary field to enable native POD parsing.
- Install cocoapods-Prefer
gem install cocoapods-prefer --user-install
- Edit your Podfile to add a binary source.
plugin 'cocoapods-prefer'
prefer_source("xxx-spec_bin_dev","[email protected]:gz/iOS/common/spec_bin_dev.git")
Copy the code
Automatically package all subspecs
- Parse Specification to generate hashMap
@code_spec = Pod::Specification.from_file(@podspec)
@spec = code_spec.dup
spec_hash = @spec.to_hash
Copy the code
- Take the subspecs and traverse the dependencies of the Subspec to the top layer
dps_hash = Hash[]
subdps = subspecs.each do |sub|
sub.delete('exclude_files')
dps_hash = dps_hash.merge(Hash(sub['dependencies']))
end
dps_hash = dps_hash.reject { |key, value| key.include?(spec_hash['name'])}
spec_hash['dependencies'] = dps_hash
Copy the code
- Iterating over the name of the subspec to the new default_subspecs
subnames = subspecs.map { |sub| sub['name']}
spec_hash['default_subspecs'] = 'xxxBin'
bin = Hash["name" => 'InkeBin']
dependencies = Hash[]
subnames.each { |name|
dependencies["#{spec_hash['name']}/#{name}"] = Array.new
}
bin['dependencies'] = dependencies
subspecs.insert(0, bin)
Copy the code
- Convert hashMap to Specification
@spec = Pod::Specification.from_hash(spec_hash)
Copy the code
- Modify the plugin, add Specification code, compile the gem, and test the subSpecs successfully packed
Optimized code
Github.com/jackyshan/c…
reference
- IOS open source binaries use the plug-in CocoapoDS-Imy-bin