title: iOS Automatic Packaging
date: 2017-02-20 15:59
tags:
- Technology
- iOS Automatic Packaging#
iOS Automatic Packaging#
Using scripts to achieve automatic packaging. I searched online for many, but I am not very smart and couldn't figure out how to use them. After a long time of searching, I finally found one that I could use, but then I realized that I couldn't use xcrun to export. It was frustrating, but I didn't say anything about it 😂. I continued to make changes and finally succeeded in figuring it out. I will share it with everyone.
Note: This is just a simple basic version. It supports projects that do not use Cocoapods. The script can be found at iOS Automatic Packaging Shell Script. If you are using a project with Cocoapods, you can make some modifications and try it out yourself. If you succeed, feel free to share it with me, 😉.
Instructions for use:
To use the iOS Automatic Packaging-sh: download the compressed file, unzip it, and you will find a .sh file and a .plist file. Place these two files in the folder where the .xcodeproj file is located. Then, open the terminal, navigate to this folder, and run the .sh file.
Now, let's talk about some problems encountered during debugging:
- Issue with file paths
- Issue with Scheme - I don't know what my scheme is, or my scheme is correct but it shows an error
- After running the script, I found that all the files became "Modified" status, and I felt really bad...
Issue 1: Problem with file paths#
Since it is a shell script, I don't have much knowledge about it. But on that Friday, my intelligence exploded and I actually understood a few lines of code. I also knew to search on Baidu (Chinese search engine). So, I successfully made the necessary changes. The script sets the path to the folder where the .xcodeproj file is located. The .xcarchive file generated during packaging is placed in the .build folder under this folder. The exported .ipa file is saved on the desktop.
Issue 2: Problem with Scheme#
If you don't know what your Scheme is, you can go to Product -> Scheme -> Edit Scheme to check.
Alternatively, you can directly run the script and it will print out the Scheme.
If you have written your own Scheme but encounter an error after running the script.
Make sure to check the "shared" option in the Edit Scheme interface.
After running the script, all files become "Modified" status#
After using "git diff" to check, I found that it was due to changes in file mode.
After changing the file mode, certain bits of the file are modified. If you strictly compare the original file with the file after changing the file mode, they will not be the same. However, the source code usually only cares about the text content, so the changes caused by changing the file mode should be ignored.
The above explanation is from a blog I found after searching on Baidu. I apologize for not being able to provide the source, as I don't remember how I found it. The solution is to enter git config core.filemode false
, and then the issue will be resolved.
Code Analysis#
- Variable declaration
project_path is the directory where this script file is located. I found this information on Baidu: Linux - Get the Absolute Path of the Currently Executing Script.
project_name is the text before .xcodeproj.
scheme_name is the one mentioned earlier.
build_path is the build folder in the current path.
exportOptionsPlistPath is the path of the plist file.
exportFilePath is the path to export the .ipa file.
- Printing the scheme, cleaning the project, building the project, and packaging
- Printing the scheme - If you don't know how to get the scheme_name, you can fill in the project_name mentioned above, comment out the code below, and run it. It will print the scheme of the current project.
- Cleaning the project - Clean before compiling...
- Building the project - Compile and generate the .xcarchive file, which is placed in the build_path folder with the name project_name.xcarchive. This step takes the most time.
- Packaging - Export the generated .xcarchive file to an .ipa file on the desktop.
Each step can be executed separately. For example, if you want to get the scheme, comment out the other code sections; if you want to test if the compilation is successful, keep only the cleaning and compilation sections; if the compilation is successful but the export fails, keep only the export section and make modifications to test it.
- Checking if the export is successful
Check if there is a scheme_name.ipa file on the desktop. If it exists, it means the packaging was successful. Open the folder containing the file.
Afterword#
a. If it is a workspace project, you can modify the cleaning, building, and packaging steps according to this link.
The content in the link above contains all the information about using xcodebuild.
b. You can refer to this link for the content of the .plist file. Please note that you need to have access to the internet to view it.
xcodebuild's new exportOptionsPlist flag