title: iOS Auto Packaging
date: 2017-02-20 15:59
- iOS Auto Packaging#
iOS Auto 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 can use, but I discovered 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 want to 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 Auto 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. 😉
To use the iOS Auto Packaging-sh: Download the compressed file, extract 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 and run the .sh file.
Now, let's talk about the problems encountered during debugging:
- Issue with file paths
- Issue with Scheme - I don't know what my Scheme is, or my Scheme is clearly correct but it shows an error
- After running the script, I found that all the files became "Modified" status, and I felt frustrated...
Problem 1: Issue with file paths#
Since it is a shell script, I don't have much knowledge about it. But on that Friday, my intelligence suddenly skyrocketed, and I actually understood a few lines of the script. I also knew to search for information online. 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 directory, and the exported .ipa file is placed on the desktop.
Problem 2: Issue with Scheme#
If you don't know what your Scheme is, you can go to Product->Scheme->Edit Scheme to check.
Or you can directly run the script and it will print it out.
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 have changed. If you strictly compare the original file with the file after changing the file mode, they are different. 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 information was found in a blog post I came across while searching online. I apologize for not being able to provide the source, as I forgot how I found it at that time. The solution is to enter "git config core.filemode false" and then it will be resolved.
- Variable declaration
project_path is the directory where this script file is located. I found this information from a search 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 scheme, cleaning the project, compiling the project, packaging
- Print the scheme. If you don't know how to get the scheme_name, you can first fill in the project_name mentioned above, comment out all the code below, and run it. It will print the scheme of the current project.
- Clean the project before compiling...
- Compile the project and generate the .xcarchive file, which is placed in the build_path with the name project_name.xcarchive. This step takes the most time.
- Package the project by exporting 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, you can comment out the other code; if you want to test if the compilation is successful, you can keep only the cleaning and compiling code; if the compilation is successful but the export fails, you can keep only the export code 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 there is, it is considered a successful packaging and the folder will be opened.
a. If it is a workspace project, you can modify the cleaning, compiling, and packaging steps according to this link:
The content in the above link is about xcodebuild, and all the usage information can be found here.
b. For the content of the .plist file, you can refer to this link (requires VPN):
xcodebuild's new exportOptionsPlist flag