用shell+ant构建apk
1 #!/bin/bash 2 ######################################################################### 3 ## $PRODVERSION:产品发布版本号码,在发布产品前由产品经理确认。 4 ## $BRANCH :代码版本分支,与stash上相同 5 ## $SECTION:Alpha,Beta,Release 6 ## @Author:Michelle Tang 7 ## @Date:2015-5-12 8 ######################################################################### 9 export PS4=‘[${BASH_SOURCE}:${LINENO}]: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }‘ 10 function show() 11 { 12 set +x 13 echo -e "\033[32;1m==============================================================\033[0m" 14 echo -e "\033[34;1m$1\033[0m" 15 echo -e "\033[32;1m==============================================================\033[0m" 16 set -x 17 } 18 function die() 19 { 20 show $1 21 exit 0 22 } 23 24 function SetBaseEnv() 25 { 26 ##Edit Test Data 27 #BRANCH="v2-uuc" 28 #SECTION="Release" 29 #PRODVERSION="v2" 30 #BUILD_NUMBER=13 31 32 export ANDROID_HOME="/backup/jenkins/bin/adt-bundle-linux/sdk" 33 export REPLACE_FILE="$HOME/ci/package/android.jar" 34 if [ x"$BRANCH" \< x"v4.2.0" ];then 35 ANDROID_TARGET="android-15" 36 else 37 ANDROID_TARGET="android-21" 38 #mv $ANDROID_HOME/platforms/$ANDROID_TARGET/android.jar android.jar.bak 39 #cp $REPLACE_FILE $ANDROID_HOME/platforms/$ANDROID_TARGET/ 40 #chmod +x $ANDROID_HOME/platforms/$ANDROID_TARGET/android.jar 41 fi 42 43 export ANT_HOME="$HOME/bin/apache-ant-1.9.2" 44 export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_55" 45 #export CLASS_PATH="$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" 46 export PATH="$PATH:$ANDROID_HOME/tools/:$ANT_HOME/bin/:$JAVA_HOME/bin" 47 48 CODE_URL="此处忽略300字...." 49 TEST_ADDR_STR="http:\/\/此处忽略300字..." 50 ONLINE_ADDR_STR="http:\/\/此处忽略300字..." 51 PROJECT_NAME="此处忽略300字..." 52 53 show "=====SetBaseEnv.End=====" 54 } 55 56 function TestEnv() 57 { 58 if [ ! -d "$ANDROID_HOME" ];then 59 die "ANDROID_HOME is not exist!" 60 elif [ ! -d "$ANT_HOME" ];then 61 die "ANT_HOME is not exist!" 62 elif [ ! -d "$JAVA_HOME" ];then 63 die "JAVA_HOME is not exist" 64 elif [ ! "$REPLACE_FILE" ];then 65 die "REPLACE_FILE is not exist!" 66 elif [ ! -d "$JAVA_HOME" ]; then 67 die "JAVA_HOME is not exist" 68 elif [ ! $REPLACE_FILE ]; then 69 die "REPLACE_FILE is not exist!" 70 else 71 show "=====TestEnv.End======" 72 return 1 73 fi 74 } 75 76 function SetKeyInfo() 77 { 78 ##set project info 79 PROJECT_NAME="此处忽略300字..." 80 PROJECT_PATH=$HOME/ci/src/$PROJECT_NAME 81 82 ## set key info 83 # set uuc key info when release uuc branch 84 if [ x"$BRANCH" == x‘v2-uuc‘ ];then 85 KEY_ALIAS_NAME="此处忽略300字..." 86 KEY_PASSWORD="此处忽略300字..." 87 KEYSTORE="此处忽略300字..." 88 KEYSTORE_PASSWORD="此处忽略300字..." 89 else 90 KEY_ALIAS_NAME="此处忽略300字..." 91 KEY_PASSWORD=$(echo "此处忽略300字..." | base64) 92 KEYSTORE="此处忽略300字..." 93 KEYSTORE_PASSWORD=$(echo "此处忽略300字..." | base64) 94 fi 95 DNAME="此处忽略300字..." 96 show "=====SetKeyInfo.End=====" 97 } 98 99 function SetAntInfo() 100 { 101 cat>> $ANT_PROPERTIES <<EOF 102 key.alias=$KEY_ALIAS_NAME 103 key.alias.password=$KEY_PASSWORD 104 key.store=$KEYSTORE 105 key.store.password=$KEYSTORE_PASSWORD 106 EOF 107 show "=====SetAntInfo.End=====" 108 } 109 110 function UpdateCode() 111 { 112 rm -rf $PROJECT_PATH 113 git clone -b $BRANCH $CODE_URL $PROJECT_PATH || die "Download code failed" 114 115 ##Set Other info 116 ANT_PROPERTIES=$PROJECT_PATH/ant.properties 117 PROJECT_PROPERTIES=$PROJECT_PATH/project.properties 118 PROGUARD_CFG=$PROJECT_PATH/proguard.cfg 119 show "======UpdateCode.End=====" 120 } 121 122 function SetUpdateAddr() 123 { 124 TARGET_FILE="此处忽略300字..." 125 if [ x$SECTION = x"Release" ]; then 126 echo "RELEASE VERSION" 127 if [ x$BRANCH = x"v3" ] || [ x$BRANCH = x"v3.1" ] ||[ x$BRANCH = x"4" ]|| [ x$BRANCH = x"v4.2.0" ] || [ x$BRANCH \> x"v4.2.0" ]; then 128 echo "BRANCH:"$BRANCH 129 test -e $TARGET_FILE || die "SetUpdateAddr file ‘DataRequestManager.java‘ is not exist!!" 130 sed -i "s/http:\/\/此处忽略300字.../$ONLINE_ADDR_STR/" $TARGET_FILE 131 sed -i "s/http:\/\/此处忽略300字.../$ONLINE_ADDR_STR/" $TARGET_FILE 132 fi 133 else 134 echo "ALPHA OR BETA VERSION" 135 if [ x$BRANCH = x"v1" ] ; then 136 TARGET_FILE="此处忽略300字..." 137 echo "BRANCH:"$BRANCH 138 test -e $TARGET_FILE || die "SetUpdateAddr file ‘此处忽略300字...‘ is not exist!" 139 sed -i "s/http:\/\/此处忽略300字.../$TEST_ADDR_STR/" $TARGET_FILE 140 elif [ x$BRANCH = x"v2" ] || [ x$BRANCH = x"v2-hd" ] || [ x$BRANCH = x"v2-hd-onetouch" ] || [ x$BRANCH = x"v2-uuc" ];then 141 echo "BRANCH:"$BRANCH 142 test -e $TARGET_FILE || die "SetUpdateAddr file ‘此处忽略300字...‘ is not exist!" 143 sed -i "s/http:\/\/此处忽略300字.../$TEST_ADDR_STR/" $TARGET_FILE 144 else 145 echo "BRANCH:"$BRANCH 146 test -e $TARGET_FILE || die "SetUpdateAddr file ‘此处忽略300字...‘ is not exist!" 147 sed -i "s/http:\/\/此处忽略300字.../$TEST_ADDR_STR/" $TARGET_FILE 148 sed -i "s/http:\/\/此处忽略300字.../$TEST_ADDR_STR/" $TARGET_FILE 149 fi 150 fi 151 show "======SetUpdateAddr=====" 152 } 153 154 function SetProguard() 155 { 156 if [ x"$SECTION" != x‘Release‘ ];then 157 sed -i ‘s/^proguard.config/#proguard.config/‘ $PROJECT_PROPERTIES 158 fi 159 show "=====SetProguard.End======" 160 } 161 162 function ReleaseProduct() 163 { 164 DATE=`date +%y%m%d%H%M%S` 165 GEN_APK="bin/${PROJECT_NAME}_${PRODVERSION}_${BUILD_NUMBER}.${DATE}_${SECTION}.apk" 166 echo ${GEN_APK} 167 cd $PROJECT_PATH 168 rm -rf ".git" 169 android update project --target ${ANDROID_TARGET} --name ${PROJECT_NAME} --path ${PROJECT_PATH} --subprojects 170 ant release 171 mv "bin/${PROJECT_NAME}-release.apk" ${GEN_APK} 172 show "======ReleaseProduct.End=====" 173 } 174 175 function CleanEnv() 176 { 177 ##Recovery android-15 178 if [ x"$ANDROID_TARGET" == x"android-15" ];then 179 cd $ANDROID_HOME/platforms/$ANDROID_TARGET/ 180 rm -f $ANDROID_HOME/platforms/$ANDROID_TARGET/android.jar 181 mv android.jar.bak android.jar 182 fi 183 show "=====CleanEnv.End=====" 184 } 185 186 function CheckSign() 187 { 188 # set uuc key info when release uuc branch 189 if [ x"$BRANCH" == x‘v2-uuc‘ ];then 190 if ! $(jarsigner -verify -verbose -certs $GEN_APK | grep -q "此处忽略300字...");then 191 die "Sign APK Failed" 192 fi 193 else 194 if ! $(jarsigner -verify -verbose -certs $GEN_APK | grep -q "此处忽略300字...");then 195 die "Sign APK Failed" 196 fi 197 fi 198 show "======CheckSign.End======" 199 } 200 201 function UploadAPK() 202 { 203 show "======UploadAPK.End======" 204 } 205 206 function main() 207 { 208 SetBaseEnv 209 TestEnv 210 if [ 1 -eq $? ];then 211 SetKeyInfo 212 UpdateCode 213 SetAntInfo 214 SetUpdateAddr 215 SetProguard 216 ReleaseProduct 217 #CleanEnv 218 CheckSign 219 #UploadAPK 220 fi 221 } 222 main
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。