├── .gitignore ├── LICENSE ├── README.md └── iOSAutoArchiveScript ├── AdHocExportOptionsPlist.plist ├── AppStoreExportOptionsPlist.plist ├── EnterpriseExportOptionsPlist.plist └── iOSAutoArchiveScript.sh /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/macos 3 | 4 | ### macOS ### 5 | *.DS_Store 6 | .AppleDouble 7 | .LSOverride 8 | 9 | # Icon must end with two \r 10 | Icon 11 | 12 | # Thumbnails 13 | ._* 14 | 15 | # Files that might appear in the root of a volume 16 | .DocumentRevisions-V100 17 | .fseventsd 18 | .Spotlight-V100 19 | .TemporaryItems 20 | .Trashes 21 | .VolumeIcon.icns 22 | .com.apple.timemachine.donotpresent 23 | 24 | # Directories potentially created on remote AFP share 25 | .AppleDB 26 | .AppleDesktop 27 | Network Trash Folder 28 | Temporary Items 29 | .apdisk 30 | 31 | # End of https://www.gitignore.io/api/macos 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 BY 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iOSAutoArchiveScript 2 | 3 | > 本脚本修改自:,十分感谢该作者! 4 | 5 | ## 更新了 Xcode 9 6 | 7 | > [Xcode 8版本点这](https://github.com/qiubaiying/iOSAutoArchiveScript/tree/xcode8) 8 | 9 | **现已经更新到 Xcode 9!** 10 | 11 | Xcode 9 的 xcodebuild 自动打包工具做了调整 12 | 13 | - Xcode 9 将不会允许你访问钥匙串里的内容,除非设置 `-allowProvisioningUpdates`。[详情请看](https://github.com/fastlane/fastlane/issues/9589) 14 | - `ExportOptions.plist` 需要添加新的 Key-Value: 15 | 16 | ``` 17 | provisioningProfiles 18 | 19 | 你的 Bundle ID 20 | 对应的PP描述文件的名称 21 | 22 | teamID 23 | 你的 teamID 24 | ``` 25 | 26 | 27 | ## 注意 28 | 29 | 30 | ~~## 注意:不能使用 ruby 2.4.0 运行该脚本~~ 31 | 32 | 该脚本在最新的 `Ruby 2.4.0` 下运行会出错(在 macOS 10.12.3 或是 10.12.4 下会编译失败,系统更新到 macOS 10.12.5 后,一切正常) 33 | 34 | 35 | 36 | 若是编译错误(一般是在导出 .ipa 包这一步),请先切换旧的 Ruby 版本再进行编译, 37 | 38 | 查看的自己 ruby 版本 39 | 40 | $ ruby -v 41 | 42 | ruby 2.3.3p222 43 | 44 | 切换 ruby 版本 45 | 46 | 如 `2.3.3` 47 | 48 | $ rvm install 2.3.3 --disable-binary 49 | $ rvm use 2.3.3 --default 50 | 51 | ## 使用方法 52 | 53 | 1. ~~切换 ruby 版本 `小于 2.4.0`~~ 54 | 55 | 2. 将 **iOSAutoArchiveScript 文件夹** 拖入到项目 **主目录!** 56 | 57 | 3. 打开 `iOSAutoArchiveScript.sh` 文件,修改 **项目自定义部分参数**,一般只需要修改两个参数 `scheme_name` 和 `build_configuration` 58 | 59 | 4. 打开终端, cd 到 **iOSAutoArchiveScript文件夹**,运行脚本 60 | 61 | $ sh iOSAutoArchiveScript.sh 62 | 63 | 64 | 最终会在桌面生成: 65 | 66 | ![](https://ww3.sinaimg.cn/large/006tNc79gy1ff27d438voj30f70avmyc.jpg) 67 | 68 | ## 上传到 Fir 69 | 70 | 添加了将ipa包上传到 [Fir](https://fir.im/) 的功能 71 | 72 | 要使用fir的上传功能,需要安装fir的命令行工具 73 | 74 | gem install fir-cli 75 | 76 | 修改配置 77 | 78 | is_fir="true" 79 | fir_token="FirAPIToken" 80 | `FirAPIToken` 在[官网](https://fir.im/)获取 81 | 82 | ![](https://ww4.sinaimg.cn/large/006tNc79gy1ff2878x1a8j304t07bt8r.jpg) 83 | 84 | 这样,导出 ipa包 成功时,就能顺带上传到 fir 了。 85 | 86 | ## 利用 自定义终端指令 简化打包过程 87 | 88 | 以zsh为例: 89 | 90 | open ~/.zshrc 91 | 92 | 添加自定义命令 `cd + sh` 93 | 94 | alias mybuild='cd 项目地址/iOSAutoArchiveScript/ && sh 项目地址/iOSAutoArchiveScript/iOSAutoArchiveScript.sh' 95 | 96 | 这样打开终端输入`mybuild`,就可以轻松实现一键打包上传了 97 | 98 | ## LICENSE 99 | 100 | [MIT License](https://github.com/qiubaiying/iOSAutoArchiveScript/blob/master/LICENSE) 101 | 102 | 103 | -------------------------------------------------------------------------------- /iOSAutoArchiveScript/AdHocExportOptionsPlist.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | provisioningProfiles 7 | 8 | com.GreenLink.GreenLink-App 9 | 对应描述文件的名称 10 | 11 | compileBitcode 12 | 13 | method 14 | ad-hoc 15 | teamID 16 | 你的teamID 17 | 18 | -------------------------------------------------------------------------------- /iOSAutoArchiveScript/AppStoreExportOptionsPlist.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | method 6 | app-store 7 | 8 | 9 | -------------------------------------------------------------------------------- /iOSAutoArchiveScript/EnterpriseExportOptionsPlist.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | provisioningProfiles 7 | 8 | com.GreenLink.GreenLink-App 9 | 对应描述文件的名称 10 | 11 | compileBitcode 12 | 13 | method 14 | enterprise 15 | teamID 16 | 你的teamID 17 | 18 | -------------------------------------------------------------------------------- /iOSAutoArchiveScript/iOSAutoArchiveScript.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | 3 | # 4 | # 联系方式 : 5 | # BY 6 | # qiubaiying@gamil.com 7 | # GitHub: https://github.com/qiubaiying/iOSAutoArchiveScript 8 | # 原作者:jkpang GitHub: https://github.com/jkpang 9 | 10 | # 11 | # =============================== 该脚本在最新的 Ruby 2.4.0 下运行会出错 ==================== 12 | # =============================== 使用前请先切换旧的 Ruby 版本 ============================= 13 | # https://github.com/jkpang/PPAutoPackageScript/issues/1 14 | 15 | 16 | # 使用方法: 17 | # step1 : 将iOSAutoArchiveScript整个文件夹拖入到项目主目录,项目主目录,项目主目录~~~(重要的事情说3遍!😊😊😊) 18 | # step2 : 打开iOSAutoArchiveScript.sh文件,修改 "项目自定义部分" 配置好项目参数 19 | # step3 : 打开终端, cd到iOSAutoArchiveScript文件夹 (ps:在终端中先输入cd ,直接拖入iOSAutoArchiveScript文件夹,回车) 20 | # step4 : 输入 sh iOSAutoArchiveScript.sh 命令,回车,开始执行此打包脚本 21 | 22 | # ===============================项目自定义部分(自定义好下列参数后再执行该脚本)============================= # 23 | # 计时 24 | SECONDS=0 25 | # 是否编译工作空间 (例:若是用Cocopods管理的.xcworkspace项目,赋值true;用Xcode默认创建的.xcodeproj,赋值false) 26 | is_workspace="true" 27 | # 指定项目的scheme名称 28 | # (注意: 因为shell定义变量时,=号两边不能留空格,若scheme_name与info_plist_name有空格,脚本运行会失败,暂时还没有解决方法,知道的还请指教!) 29 | scheme_name="you_scheme_name" 30 | # 工程中Target对应的配置plist文件名称, Xcode默认的配置文件为Info.plist 31 | info_plist_name="Info" 32 | # 指定要打包编译的方式 : Release,Debug,或者自定义的编译方式 33 | build_configuration="AdHoc" 34 | 35 | # ===============================项目上传部分============================= # 36 | # 上传到fir , 37 | # 需要先安装fir的命令行工具 38 | # gem install fir-cli 39 | # 是否上传到fir,是true 否false 40 | is_fir="true" 41 | # 在 fir 上的API Token 42 | fir_token="you_fir_Token" 43 | 44 | # ===============================自动打包部分(无特殊情况不用修改)============================= # 45 | 46 | # 导出ipa所需要的plist文件路径 (默认为AdHocExportOptionsPlist.plist) 47 | ExportOptionsPlistPath="./iOSAutoArchiveScript/AdHocExportOptionsPlist.plist" 48 | # 返回上一级目录,进入项目工程目录 49 | cd .. 50 | # 获取项目名称 51 | project_name=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'` 52 | # 获取版本号,内部版本号,bundleID 53 | InfoPlistPath="$project_name/$info_plist_name.plist" 54 | bundle_version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $InfoPlistPath` 55 | bundle_build_version=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $InfoPlistPath` 56 | bundle_identifier=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $InfoPlistPath` 57 | 58 | 59 | # 指定输出ipa路径 60 | export_path=~/AutoArchive/$scheme_name-IPA 61 | # 指定输出归档文件地址 62 | export_archive_path="$export_path/$scheme_name.xcarchive" 63 | # 指定输出ipa地址 64 | export_ipa_path="$export_path" 65 | # 指定输出ipa名称 : scheme_name + bundle_version 66 | ipa_name="$scheme_name-v$bundle_version" 67 | 68 | 69 | # AdHoc,AppStore,Enterprise三种打包方式的区别: http://blog.csdn.net/lwjok2007/article/details/46379945 70 | echo "================请选择打包方式(输入序号,按回车即可)================" 71 | echo " 1 AdHoc 内测 " 72 | echo " 2 AppStore 上架 " 73 | echo " 3 Enterprise 企业 " 74 | echo " 4 Exit 退出 " 75 | echo "================请选择打包方式(输入序号,按回车即可)================" 76 | # 读取用户输入并存到变量里 77 | read parameter 78 | sleep 0.5 79 | method="$parameter" 80 | 81 | # 判读用户是否有输入 82 | if [ -n "$method" ] 83 | then 84 | if [ "$method" = "1" ] ; then 85 | ExportOptionsPlistPath="./iOSAutoArchiveScript/AdHocExportOptionsPlist.plist" 86 | elif [ "$method" = "2" ] ; then 87 | ExportOptionsPlistPath="./iOSAutoArchiveScript/AppStoreExportOptionsPlist.plist" 88 | elif [ "$method" = "3" ] ; then 89 | ExportOptionsPlistPath="./iOSAutoArchiveScript/EnterpriseExportOptionsPlist.plist" 90 | elif [ "$method" = "4" ] ; then 91 | echo "退出!" 92 | exit 1 93 | else 94 | echo "输入的参数无效,请重新选择!!!" 95 | exit 1 96 | fi 97 | fi 98 | 99 | echo "**************************删除旧编译文件与ipa...*********************************" 100 | # 删除旧.xcarchive文件 101 | rm -rf ~/AutoArchive/$scheme_name-IPA/$scheme_name.xcarchive 102 | # 删除旧.xcarchive文件 103 | rm -rf ~/AutoArchive/$scheme_name-IPA/$ipa_name.ipa 104 | 105 | echo "**************************开始编译代码...*********************************" 106 | # 指定输出文件目录不存在则创建 107 | if [ -d "$export_path" ] ; then 108 | echo $export_path 109 | else 110 | mkdir -pv $export_path 111 | fi 112 | 113 | # 判断编译的项目类型是workspace还是project 114 | if $is_workspace ; then 115 | # 编译前清理工程 116 | xcodebuild clean -workspace ${project_name}.xcworkspace \ 117 | -scheme ${scheme_name} \ 118 | -configuration ${build_configuration} 119 | 120 | xcodebuild archive -workspace ${project_name}.xcworkspace \ 121 | -scheme ${scheme_name} \ 122 | -configuration ${build_configuration} \ 123 | -archivePath ${export_archive_path} 124 | else 125 | # 编译前清理工程 126 | xcodebuild clean -project ${project_name}.xcodeproj \ 127 | -scheme ${scheme_name} \ 128 | -configuration ${build_configuration} 129 | 130 | xcodebuild archive -project ${project_name}.xcodeproj \ 131 | -scheme ${scheme_name} \ 132 | -configuration ${build_configuration} \ 133 | -archivePath ${export_archive_path} 134 | fi 135 | 136 | # 检查是否构建成功 137 | # xcarchive 实际是一个文件夹不是一个文件所以使用 -d 判断 138 | if [ -d "$export_archive_path" ] ; then 139 | echo " ✅ ✅ ✅ ✅ ✅ ✅ 编译成功 ✅ ✅ ✅ ✅ ✅ ✅ " 140 | else 141 | echo " ❌ ❌ ❌ ❌ ❌ ❌ 编译失败 ❌ ❌ ❌ ❌ ❌ ❌ " 142 | exit 1 143 | fi 144 | 145 | echo "**************************开始导出ipa文件....*********************************" 146 | # Xcode9需要加上 -allowProvisioningUpdates 147 | # 详情看:https://github.com/fastlane/fastlane/issues/9589 148 | xcodebuild -exportArchive \ 149 | -archivePath ${export_archive_path} \ 150 | -exportPath ${export_ipa_path} \ 151 | -exportOptionsPlist ${ExportOptionsPlistPath} \ 152 | -allowProvisioningUpdates 153 | # 修改ipa文件名称 154 | mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name.ipa 155 | 156 | # 检查文件是否存在 157 | if [ -f "$export_ipa_path/$ipa_name.ipa" ] ; then 158 | echo "🎉 🎉 🎉 🎉 🎉 🎉 ${ipa_name} 打包成功! 🎉 🎉 🎉 🎉 🎉 🎉 " 159 | open $export_path 160 | else 161 | echo "❌ ❌ ❌ ❌ ❌ ❌ ${ipa_name} 打包失败! ❌ ❌ ❌ ❌ ❌ ❌ " 162 | exit 1 163 | fi 164 | 165 | # 输出打包总用时 166 | echo "打包总用时: ${SECONDS}s ~~~~~~~~~~~~~~~~" 167 | 168 | # 上传 169 | if $is_fir ; then 170 | echo "**************************开始上传ipa文件....*********************************" 171 | fir publish "$export_ipa_path/$ipa_name.ipa" -T ${fir_token} 172 | echo "fir publish "$export_ipa_path/$ipa_name.ipa" -T ${fir_token}" 173 | echo "总计用时:${SECONDS}" 174 | else 175 | exit 1 176 | fi 177 | --------------------------------------------------------------------------------