IOS Automatic packaging

Use script to implement automatic packaging, I searched a lot on the Internet, but I am stupid, I always found that I do not know how to use, look for a long time, finally changed a can use, but finally found that it cannot use xcRun export; Baby heart bitter, but the baby don’t say 😂; Then change, finally I tampered with success, share with you

Note: This is a simple base version of Cocoapods that does not use Cocoapods. For the script, see the iOS autopackage _shell script. If you use The Cocoapods project, you can modify it a little bit and encourage you to try it out for yourself and share it with me at 😉

Usage:

IOS automatic packaging -sh use: Xcodeproj, ProjectName and SchemeName, open terminal, and run the.sh file.

Then let’s talk about the problems encountered in debugging:

  1. File path problem
  2. I don’t know what my sheme is. Or my sheme is just this and it says I can’t find it
  3. After the script is run, all files are Modified, and I suddenly feel bad.

Problem 1: Path problem

Because it’s a shell script, I don’t know much about it. On Friday, I was so smart that I actually understood a few sentences and found baidu, so I changed it successfully. The path of the script is set to the folder where XcodeProJ is located. The packaged.xcarchive files are stored in the.build folder under this folder, and the exported IPA files are stored on the desktop

Problem 2: Scheme problem

If you don’t know what your Scheme is, go to Product->Scheme->Edit Scheme

Or just run the script and it will print out

Error: write your own Scheme but run script

Note that shared is checked in the Edit Scheme interface

After the script runs, all files change to the Modified state

Git diff is a change to Filemode

Some bits of the chmod file change, and if you strictly compare the original file with the chmod file, they are not the same, but source code usually only cares about the text content, so chmod changes should be ignored

The above is to find Baidu, found in the blog introduced, please forgive me, forget how to search, all can not find the source, the text was screenshots at that time… Git config core.filemode false and you’re done

The code analysis

  1. Variable declarations

    Project_path is the directory where the script file is located, found on BaiduLinux- Gets the absolute path of the currently executing script

    Project_name is the text before.xcodeProj

    Scheme_name is the previous one

    Build_path is the build folder in the current path

    ExportOptionsPlistPath is the path of the PList file

    ExportFilePath is the path for exporting the. Ipa package

  2. Print scheme, clean project, compile project, package

    Print scheme_name. If you don’t know how to get scheme_name, you can fill in project_name above, comment out all the following code, and run to print the scheme of the current project

    Clean up project, clean up before compiling…

    Build the project, compile and generate the.xcarchive file under build_path named project_name.xcarchive, which is the most time-consuming step

    Package and export the generated. Xcarchive file to the. Ipa package on the desktop

Each of these steps can be performed separately. For example, if you want to get shceme, you can comment out several other pieces of code. If you want to test whether the compile passed, only the clean, compile section; If the compilation succeeds and the export fails, only the exported section is retained and the test is modified

  1. Check whether the export is successful

    Check whether there is a scheme_name.ipa file on the desktop. If there is, the package is considered successful.

Afterword.

A. If it is a workspace project, you can follow the link here to modify the cleaning project, compiling project and packaging steps

xcodebuild-developer.apple

This is the content of the link above, where xcodeBuild is used

Xcodebuild’s new exportOptionsPlist flag