Github open source, with a detailed tutorial
An overview,
It’s been almost half a year since the last post on binary compilation for iOS (how iOS can build more than 10 times faster), and I’ve received a lot of support from my friends. Cocoapods-imy-bin this system is also in our company (Us) run over tens of thousands of packaging records, the current performance is still very stable.
In view of the current market, Swift and Swift-OC mixed projects are popular, and Swift compilation project is too slow, in the fault of busy business, the binary componentization of Swift and Swift-OC projects is supported. Hope to give friends in iOS compilation issues, to provide help.
Ii. Project effect
Our CocoapoDS-Imy-bin project also supports binarization of pure Swift, pure object-C, and swift-OC.
See the effect directly from the picture above, and I won’t say much more. This paper experiments swift-oc-demo address, interested partners can download to verify the effect.
Figure 1. Comparison of Build Tasks
Figure 2. Build time comparison
Figure 1. The number of compiled tasks is 532\113 when binary is not used. The number of compiled tasks is some other files, link, copy file, sign and other tasks except Pods library, which is reduced by 80%.
Figure 2. Compilation time: When binary is not used, the compilation time is 35.9s\17.8s, 17.8s is the time of some other files, link, copy file, sign and so on except Pods library. The efficiency is increased by 2 times.
Figure 3. Comparison of Compilation time of Meiyu App
In terms of overall efficiency, the improvement of compilation speed is very considerable. The larger the project, the more obvious the performance improvement. In our Meiyou APP project, the compilation speed can reach more than 13 times. (Full compilation)
Three, cocoapoDS-IMy-bin project function
Automatic support for iOS project component binaries:
- No intrusion, no perception, no impact on the existing business, no impact on the existing code framework, completely green products ~
- Lightweight, and can be used as long as the project can compile and pass, ignoring componentization and coupling
- Fully automatic, one key use, no manual operation
- Support for use and not use
use_frameworks!
- Offers several features
- One of the few open source projects that supports binary compilation of the Swift project
Introduction to Swift binarization
Currently, Demo is a swift-OC hybrid and supports pure Swift projects. Oc-demo is here, the detailed principles and details please move to iOS how to improve the compilation speed of more than 10 times.
The Swift binarization principle is just that — it’s all automatically converted to the Framework in POD
FIG. 4
Figure 5. Automatic conversion relies on binary components
5. Problems encountered in Swift binarization
Module Compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.2 compiler
Solution:
Set Build Libraries for Distribution to YES in the Build Setting of the Framework, otherwise the Swift compiler will not generate the necessary “. Swiftinterface “file. This is the key to future compilers being able to load older libraries.
2. If there are not many machines, you can update Xcode to a unified version number
2. OC references Swift file under {Development Pods
Solution :(suggest shell engineering, can avoid this problem)
This file is the objective-C header for the Swift file that the system generated when it was mixed, You can run Targets–>Build Settings–>Swift compiler-general –> objective-c Generated Interface Header Name to configure Targets–>Build Settings–>Swift compiler-general –> Objective-c Generated Interface Header Name The default file name is the project name -swift. h, and is generally left unchanged.
3,Podfile use_frameworks reference! With no reference to use_frameworks! The compilation problem of
< Products/ debug-iphonesimulator /lottie-ios/lottie-ios.framework/Headers > < Products/ debug-iphonesimulator /lottie-ios/lottie-ios.framework/Headers Remove the * * use_frameworks! I can’t find it
Solution: Add the file reference in Header Search Paths
4,Command PhaseScriptExecution failed with a nonzero exit code
Fixed: cocopods1.8.4 will have this problem, after 1.9.1 will be normal
5,Masonry
. which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may setuse_modular_headers!
globally in your Podfile, or specify :modular_headers => true
for particular dependencies.
Pod bin Auto
Solution: Modify cocoapods plug-in code, or use cocopoda -imy-bin V0.3.11 version can be solved.
# setting modular_headers_for
if(target_definition && target_definition.use_modular_headers_hash.values.any?)
target_definition.use_modular_headers_hash.values.each do |f|
f.each { | pod_name| self.set_use_modular_headers_for_pod(pod_name, true)}end
end
Copy the code
Welcome to join us pomelo family, can help you push. Send your resume to [email protected]