App Thinning, appthinning
App Thinning
Because Bitcode compilation must be enabled in the project, Bitcode has some misunderstandings before, so I have sorted out the relevant knowledge for reference only. If there is any error, please note.
Currently, iOS App compilation and packaging combines execution files and resource files compatible with multiple devices into one file. The uploaded and downloaded files include all these files, this results in a large amount of storage space.
App Thinning is a function to save the storage space of iOS devices. It allows iOS devices to download only the required resources in scenarios such as installation, update, and running of apps, reducing App space occupation, this saves device storage space.
According to the official Apple documentation, App Thinning has three mechanisms:
1. Slicing
After the developer uploads the App installation package to the AppStore, the Apple service Automatically splits the installation package into different application variants (App variant). When the user downloads the installation package, the system downloads and installs a single application variation based on the device model. (Supported by iOS9.0.2 or later)
For backward compatibility, iOS apps now contain both 32-bit and 64-bit slice. In terms of image resources, there are all 2x 3x images available (1x is not needed now ). When users use an app, because the device is specific, they only need a set of resources. However, the entire app package is downloaded during purchase and download. Apple finally realized how silly it was. In iOS 9, you can finally download only the desired content (Slicing. For developers, there is not much to do. You only need to use asset catalog to manage the material mark 2x 3x.
Finally, Apple downloads resources as follows:
2. Bitcode
After Bitcode compilation is enabled, developers can upload Intermediate Representation (middleware) instead of the final executable binary file when uploading apps. Before a user downloads an App, The AppStore automatically compiles the middleware and generates the execution file required by the device for the user to download and install. That is, when we submit a program to the App Store, Xcode will compile the program into an intermediate representation (bitcode ). App store then compiles the Bitcode into a 64-bit or 32-bit program that can be executed. Apple will generate binary codes containing only the instruction set for the mobile phone of the user who downloaded the application and issue the code. To streamline the size of the installation package.
Bitcode is an encoding of the intermediate code of the LLVM compiler. The front-end of the LLVM can be understood as a programming language such as C/C ++/OC/Swift, the back-end of LLVM can be understood as the assembly instruction or executable machine instruction data on each chip platform. BitCode is the intermediate code directly located between the two. The principle of LLVM compilation is that the front-end is responsible for translating the project source code into Bitcode intermediate code, and then converting the program source code to the corresponding assembly instructions and machine code based on the different target machine chip platforms. This design makes LLVM a compiler architecture, and can easily invent new languages (front-ends) on the LLVM architecture, as well as support for new CPUs (backend) under the LLVM architecture) command output.
Although Bitcode is only an intermediate code that cannot be run on any platform, it can be converted to any supported CPU architecture, including the CPU architecture that has not yet been invented, that is to say, the Bitcode function is now enabled to submit an App to the App Store. This mechanism ensures that developers are compatible with new devices without re-releasing Apple hardware. For example, if Apple has a new mobile phone and the CPU architecture is completely new, the App's Bitcode can be compiled and converted into executable programs on the new CPU on the Apple background server, this App can be downloaded and run by new mobile users.
You can see in the document
In fact, app slicing handles
Majority of the app thinning process. 'app slicing' feature finally switched on in iOS 9.0.2
It indicates that slicing is mainly used to process app thinning, and this function must be later than iOS9.0.2 (iOS9.0 is disabled because of an iCloud bug ). In fact, Bitcode is used to optimize the instruction set. Perform compilation Optimization Based on the status of your device to improve performance. Therefore, Bitcode does not play an essential role in optimizing the package size.
Bitcode considerations
1. Bitcode is enabled for Xcode 7 by default. If Bitcode is enabled for an application, other third-party libraries integrated by the application must be Bitcode-compiled packages for Bitcode compilation.
2. after Bitcode compilation is enabled. the app size will increase (intermediate code, not the package downloaded by the user), and. the dSYM file cannot be used as a symbolic means of crash logs (the downloaded package is generated by recompilation by the Apple Service and a new symbolic file is generated)
3. Upload the AppStore package in Archive mode. You can download the new symbol file of the corresponding installation package from Xcode's Organizer tool.
3. On-Demand Resources
ORD (On-demand Resource) means that after a developer adds a tag to the resource for upload, the system dynamically downloads and loads the required resources based on the App running status. When the storage space is insufficient, this type of resource is automatically deleted.
This may be applicable in more scenarios in the game. You can use tags to organize resources like images or sounds, such as marking them as level1 and level2. Then, you only need to download the content of level1 at the beginning, and then download level2 during the playing process. You can also use this to download the resource files that require in-house purchases.
4. Test
Check the effect of enabling or disabling Bitcode on the package size.
The test method is as follows:
Export ipa in Development Mode:
The second method is used to generate a package for a specific model.
Then you can see Compiling Bitcode!
The final result is displayed in the final output file of the App Thinning, which contains the ipa package for each model.
The final test result is as follows: it can be seen that enabling Bitcode has little impact on the package size. In addition, the size of the ipa package here is not the size shown in the AppStore. The size here is the size of the actual user download (the size of the mobile phone disk ).
Reference
Apple official introduction
Working with App Thinning in iOS 9
Bitcode adaptation Guide
In-depth understanding of the BitCode feature in iOS development