gradlew.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #!/bin/sh
  2. # 编码要求:
  3. # 所有全大写变量均为全局变量;
  4. # 函数内部变量请使用非全大写;
  5. # 主目录;
  6. WORK_HOME="/home/data/ApkAutoCompile"
  7. # 参数1:apk源码路径;
  8. APK_SRC_DIR=$1
  9. # apk名称,源于源码路径,需要对带 _General 的删除后缀。
  10. APK_NAME=''
  11. # debug apk的svn版本号;
  12. APK_DEBUG_SVN_REVISION=$3
  13. # Debug Apk 根地址;
  14. APK_DEBUG_ROOT_URL='https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/app/apk/01debug/general'
  15. # Release Apk 根地址;
  16. APK_RELEASE_ROOT_URL='https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/app/apk/02release/general'
  17. # Apk源码根地址;
  18. APK_SRC_ROOT_URL='https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/app/src'
  19. # APK 根路径;
  20. APK_ROOT_DIR="${WORK_HOME}/cacheAPK/general"
  21. # Debug Apk 根路径;
  22. APK_DEBUG_ROOT_DIR="${APK_ROOT_DIR}/Debug"
  23. # Release Apk 根路径;
  24. APK_RELEASE_ROOT_DIR="${APK_ROOT_DIR}/Release"
  25. # Debug Apk Log
  26. APK_DEBUG_LOG=$4
  27. # Gradle目录;
  28. GRADLE_HOME=/home/data/android/gradle/gradle-6.7.1
  29. # Android SDK 目录;
  30. ANDROID_SDK_HOME=/home/data/android/android_sdk/android-sdk-linux
  31. # 是否重新编译;
  32. REBUILD=$2
  33. # 当前要处理的APK的SVN路径;
  34. APK_SRC_URL=''
  35. # Build的apk路径;
  36. APK_BUILD_DIR=''
  37. # debug Apk 路径;
  38. APK_DEBUG_DIR=''
  39. # debug Apk 路径;
  40. APK_RELEASE_DIR=''
  41. # APK的版本号
  42. APK_VER_CODE=''
  43. # 中间件服务APK<https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/TVMidware/debug/TVMidwareService>;
  44. APK_DIR_TVMidware="/home/data/ApkAutoCompile/cacheAPK/TVMidware"
  45. # 日期;
  46. CURR_TIME=$(date +"%Y-%m-%d %T")
  47. # 仓库类型:SVN或GIT
  48. REPO_TYPE='SVN'
  49. # 日志文件;
  50. if [ ! -d '/home/data/ApkAutoCompile/shell/log' ];then
  51. mkdir '/home/data/ApkAutoCompile/shell/log'
  52. fi
  53. LOG_FILE="/home/data/ApkAutoCompile/shell/log/gradlew-${APK_NAME}-$(date '+%d-%H%M%S').log"
  54. SwitchIntranet()
  55. {
  56. echo -e "\r\r---切换到内网---"
  57. route del default gw 10.201.40.1
  58. sleep 3s
  59. route del default gw 10.201.40.1
  60. sleep 3s
  61. route add default gw 10.201.40.1
  62. sleep 3s
  63. route add default gw 10.201.40.1
  64. }
  65. SwitchExternal()
  66. {
  67. echo -e "\r\r---切换到外网---"
  68. route del default gw 10.201.40.1
  69. sleep 3s
  70. route del default gw 10.201.40.1
  71. sleep 3s
  72. route del default gw 10.201.40.1
  73. }
  74. debug_apk_svn_commit()
  75. {
  76. echo -e "func-> debug_apk_svn_commit\n"
  77. SVN_DEBUG_APK_PATH=$1
  78. if [ -d ${SVN_DEBUG_APK_PATH} ];then
  79. local count=0
  80. cd ${SVN_DEBUG_APK_PATH}
  81. # 查找未提交或变更的文件;
  82. filelist=$(svn status)
  83. # 以"? "分组字符串;
  84. filearray=(${filelist//? /})
  85. for File in ${filearray[@]}
  86. do
  87. let count+=1
  88. # 如果是文件;
  89. if [ -f ${File} ];then
  90. msg=$(svn add ${File} 2>&1)
  91. echo -e "svn add file = ${File}, result=${msg}\n"
  92. elif [ -d ${File} ];then
  93. msg=$(svn add ${File} 2>&1)
  94. echo -e "svn add dir = ${File}, result=${msg}\n"
  95. fi
  96. done
  97. # 提交;
  98. echo "变化文件数量 = ${count}"
  99. if [ $count -gt 0 ];then
  100. cd ${SVN_DEBUG_APK_PATH}
  101. # 判断源码路径类型;
  102. if [ x${REPO_TYPE} == x'GIT' ];then
  103. echo "源码路径为git"
  104. # 获取源码版本;
  105. cd ${APK_SRC_DIR}
  106. shortId=$(git rev-parse --short HEAD 2>&1)
  107. lastChangedRev="Last Changed Rev: ${shortId}"
  108. cd ${SVN_DEBUG_APK_PATH}
  109. else
  110. # 获取源码版本;
  111. echo "源码路径为svn"
  112. lastChangedRev=$(svn info ${APK_SRC_DIR}|grep "Last Changed Rev" 2>&1)
  113. fi
  114. msg=$(svn commit -m "upgrade ${APK_NAME}.${APK_VER_CODE}. ${lastChangedRev}" 2>&1)
  115. echo -e "svn commit result=${msg}\n"
  116. if [[ $msg != *"Committed revision"* ]]; then
  117. echo -e "svn_commit:连接SVN服务器失败, 网络异常!\n"
  118. SwitchIntranet
  119. return 0
  120. else
  121. echo -e "提交svn成功\n"
  122. return 1
  123. fi
  124. else
  125. echo -e "无文件变化,不需要提交svn\n"
  126. return 0
  127. fi
  128. else
  129. echo -e "目录<${SVN_DEBUG_APK_PATH}>不存在,无法提交.\n"
  130. return 0
  131. fi
  132. }
  133. commitAPK(){
  134. echo "---------commitAPK------------"
  135. # 切回内网;
  136. SwitchIntranet
  137. sleep 10s
  138. echo "apk name = "${APK_NAME}
  139. if [ x${APK_NAME} == "xMiddleCommon" ];then
  140. if [ -d ${APK_DIR_TVMidware} ]; then
  141. cd ${APK_DIR_TVMidware}
  142. rm *
  143. fi
  144. svn_result=$(svn up 2>&1)
  145. if [[ $svn_result != *"Updated to revision"* ]] && [[ $svn_result != *"At revision"* ]]; then
  146. echo -e "svn up:连接SVN服务器失败, 网络异常!\n"
  147. fi
  148. cp ${APK_BUILD_DIR} ${APK_DIR_TVMidware}
  149. debug_apk_svn_commit ${APK_DIR_TVMidware}
  150. ls -l ${APK_DIR_TVMidware}
  151. else
  152. # copy apk
  153. if [ -d ${APK_DEBUG_DIR} ]; then
  154. cd ${APK_DEBUG_DIR}
  155. echo -e "APK_DEBUG_DIR=${APK_DEBUG_DIR}\n"
  156. ls -l ${APK_DEBUG_DIR}
  157. rm *
  158. svn_result=$(svn up 2>&1)
  159. echo -e "commitAPK:svn up结果=${svn_result}\n"
  160. if [[ $svn_result != *"Updated to revision"* ]] && [[ $svn_result != *"At revision"* ]]; then
  161. echo -e "commitAPK:连接SVN服务器失败, 网络异常!\n"
  162. SwitchIntranet
  163. fi
  164. else
  165. mkdir -p ${APK_DEBUG_DIR}
  166. fi
  167. cd ${APK_DEBUG_DIR}
  168. svn_lastChangedDate=$(svn info ${APK_SRC_DIR}|grep Date 2>&1)
  169. svn_lastChangedRev=$(svn info ${APK_SRC_DIR}|grep "Last Changed Rev" 2>&1)
  170. cp ${APK_BUILD_DIR} ${APK_DEBUG_DIR}
  171. debug_apk_svn_commit ${APK_DEBUG_DIR}
  172. echo -e "After apk copy, APK_DEBUG_DIR:"
  173. ls -l ${APK_DEBUG_DIR}
  174. fi
  175. #ensure under shell folder
  176. cd ${WORK_HOME}/shell
  177. echo -e "WORK_HOME PWD:$(pwd)\n"
  178. python3 -c "import builder;builder.updateProjectRev('$APK_SRC_DIR','$svn_lastChangedRev','$svn_lastChangedDate')"
  179. }
  180. compileGeneralApp()
  181. {
  182. echo "enter compileGeneralApp"
  183. # 需要单独处理两APK:FastCastTV、FastScreenV3.0的版本号获取问题
  184. if [ x${APK_NAME} == "xFastCastTV" ];then
  185. echo -e "\t单独处理此APK Local_FastScreenTV_CN"
  186. appVCodeT=$(cat "${APK_SRC_DIR}/Local_FastScreenTV/build.gradle"|grep versionCode |grep -v "getVersionNameByCode\|=\|flavorDimensions")
  187. elif [ x${APK_NAME} == "xFastScreenV3.0" ];then
  188. echo -e "\t单独处理此APK FastScreenV3.0"
  189. appVCodeT=$(cat "${APK_SRC_DIR}/AdvertisementActivity/build.gradle"|grep versionCode |grep -v "getVersionNameByCode\|=\|flavorDimensions")
  190. else
  191. appVCodeT=$(cat "${APK_SRC_DIR}/app/build.gradle"|grep versionCode |grep -v "getVersionNameByCode\|=\|flavorDimensions")
  192. fi
  193. # 查找apk版本号
  194. echo "appVCodeT=${appVCodeT}"
  195. if [ ${#appVCodeT} -eq 0 ];then
  196. echo -e "\tappVCode error"
  197. else
  198. vCode=$(echo $appVCodeT | tr -cd "[0-9]")
  199. echo -e "\tappVCode number:"$vCode
  200. mainVersionCode=$(expr $vCode / 100)
  201. childVersionCode=$(expr $vCode % 100)
  202. appDate=$(date +%Y%m%d)
  203. APK_VER_CODE="appVersionName:"$mainVersionCode"."$childVersionCode"."$appDate
  204. echo -e "\t$APK_VER_CODE"
  205. fi
  206. # route to google
  207. SwitchExternal
  208. sleep 10s
  209. #get release packet name
  210. releaseName=$(python3 -c 'import builder;print(builder.getReleaseName("'$APK_SRC_DIR'"))')
  211. echo -e "\treleaseName:"${releaseName}
  212. #compile app for release apk
  213. cp sabuild/local.properties $APK_SRC_DIR
  214. cd "$APK_SRC_DIR"
  215. echo -e "\tAPK_SRC_DIR,PWD:$(pwd)"
  216. chmod +x gradlew
  217. gradle --version
  218. # 修改 adle/wrapper/gradle-wrapper.properties distributionUrl 路径为本地;
  219. # home/data/ApkAutoCompile/cacheAndroidSrc/Factory_General/gradle/wrapper/gradle-wrapper.properties
  220. GradlePro=${APK_SRC_DIR}/gradle/wrapper/gradle-wrapper.properties
  221. sed -i "s/https\\\:\/\/services.gradle.org\/distributions/file:\/\/\/home\/local_gradle/" ${GradlePro}
  222. # 判断文件是否存在;
  223. if [ -f "build.sh" ];then
  224. echo -e "\tbuild.sh"
  225. chmod +x build.sh
  226. ./build.sh
  227. else
  228. echo -e "\tNo build.sh"
  229. ./gradlew ${releaseName}
  230. fi
  231. #commit apk
  232. APK_BUILD_DIR=$(find ${APK_SRC_DIR} -name "*.apk")
  233. echo -e "\tAPK_BUILD_DIR:${APK_BUILD_DIR}"
  234. if [ ${#APK_BUILD_DIR} -eq 0 ];then
  235. echo -e "\tcompile apk fail"
  236. else
  237. tmp1=${APK_NAME%*_General}
  238. echo -e "\t==========APK_NAME=" ${APK_NAME}
  239. echo -e "\t==========tmp1=" ${tmp1}
  240. # P_APK_DIR="${APK_DIR_general}/${tmp1#*TIF_}"
  241. APK_DEBUG_DIR="${APK_DEBUG_ROOT_DIR}/${tmp1}"
  242. echo -e "\t==========APK_DEBUG_DIR=" ${APK_DEBUG_DIR}
  243. if [ ! -d ${APK_DEBUG_DIR} ];then
  244. mkdir ${APK_DEBUG_DIR}
  245. fi
  246. commitAPK
  247. fi
  248. }
  249. compileCustomApp(){
  250. echo -e "\tenter compileCustomApp"
  251. apkSections=$(python3 -c 'import builder;print(builder.getAPKSection("'$APK_SRC_DIR'"))')
  252. echo -e "\tapkSections:"${apkSections}
  253. }
  254. # 函数:是否需要更新本地svn目录;
  255. # 描述:判断本地svn目录版本与服务器版本是否一致;
  256. # 返回:0表示不需要更新本地svn目录, 1表示需要更新;
  257. IsUpdateSVN()
  258. {
  259. echo -e "\n\n==========执行函数:IsUpdate=========="
  260. SwitchIntranet
  261. # 如果目录不存在,直接返回需要更新;
  262. if [ ! -d ${APK_SRC_DIR} ]; then
  263. echo -e "目录[${APK_SRC_DIR}]不存在,需要更新\n"
  264. return 1
  265. fi
  266. # 获取本地目录的最新提交版本;
  267. svn_local_lcr=$(svn info ${APK_SRC_DIR}|grep "Last Changed Rev" 2>&1)
  268. echo -e "\r\r获取本地目录的最新提交版本="${svn_local_lcr}
  269. svn_local_lcr=${svn_local_lcr#*Last Changed Rev: }
  270. echo -e "\r\nLocal SVN Last Changed Revision=${svn_local_lcr}"
  271. # 查找服务器的地址;
  272. cd ${APK_SRC_DIR}
  273. APK_SRC_URL=$(svn info|grep "URL:" |grep -v "Relative URL:" 2>&1)
  274. echo -e "${APK_SRC_URL}"
  275. APK_SRC_URL=${APK_SRC_URL#*URL:}
  276. cd -
  277. # 获取服务器的最新提交版本;
  278. svn_server_lcr=$(svn info ${APK_SRC_URL}|grep "Last Changed Rev" 2>&1)
  279. if [[ $svn_server_lcr == *"svn: E170013: Unable to connect to a repository at URL"* ]]; then
  280. echo -e "连接SVN服务器失败, 网络异常=${svn_server_lcr}!\n"
  281. SwitchIntranet
  282. return 0
  283. fi
  284. svn_server_lcr=${svn_server_lcr#*Last Changed Rev: }
  285. echo -e "Server SVN Last Changed Revision=${svn_server_lcr}"
  286. # 比较版本号或日期;
  287. if [ ${svn_server_lcr} -gt ${svn_local_lcr} ];then
  288. echo -e "服务器版本大于本地目录版本号,需要更新"
  289. return 1
  290. fi
  291. if [ x${REBUILD} == "x1" ]; then
  292. echo -e "手动编译标记位"
  293. return 1
  294. fi
  295. echo -e "本地版本与服务器版本相同 ,不需要更新\n"
  296. return 0
  297. }
  298. IsUpdateGIT()
  299. {
  300. SwitchIntranet
  301. echo -e "\n\n==========执行函数:IsUpdate=========="
  302. # 如果目录不存在,直接返回需要更新;
  303. if [ ! -d ${APK_SRC_DIR} ]; then
  304. echo -e "\t目录[${APK_SRC_DIR}]不存在,需要更新\n"
  305. return 1
  306. fi
  307. # 获取本地目录的最新提交版本;
  308. svn_local_lcr=$(svn info ${APK_SRC_DIR}|grep "Last Changed Rev" 2>&1)
  309. echo -e "\r\r获取本地目录的最新提交版本="${svn_local_lcr}
  310. svn_local_lcr=${svn_local_lcr#*Last Changed Rev: }
  311. echo -e "\r\nLocal SVN Last Changed Revision=${svn_local_lcr}"
  312. # 查找服务器的地址;
  313. cd ${APK_SRC_DIR}
  314. APK_SRC_URL=$(svn info|grep "URL:" |grep -v "Relative URL:" 2>&1)
  315. echo -e "\t${APK_SRC_URL}"
  316. APK_SRC_URL=${APK_SRC_URL#*URL:}
  317. cd -
  318. # 获取服务器的最新提交版本;
  319. svn_server_lcr=$(svn info ${APK_SRC_URL}|grep "Last Changed Rev" 2>&1)
  320. if [[ $svn_server_lcr == *"svn: E170013: Unable to connect to a repository at URL"* ]]; then
  321. echo -e "\t连接SVN服务器失败, 网络异常=${svn_server_lcr}!\n"
  322. SwitchIntranet
  323. exit
  324. fi
  325. svn_server_lcr=${svn_server_lcr#*Last Changed Rev: }
  326. echo -e "\tServer SVN Last Changed Revision=${svn_server_lcr}"
  327. # 比较版本号或日期;
  328. if [ ${svn_server_lcr} -gt ${svn_local_lcr} ];then
  329. echo -e "\t服务器版本大于本地目录版本号,需要更新"
  330. return 1
  331. fi
  332. if [ x${REBUILD} == "x1" ]; then
  333. echo -e "\t手动编译标记位"
  334. return 1
  335. fi
  336. echo -e "\t本地版本与服务器版本相同 ,不需要更新\n"
  337. return 0
  338. }
  339. UpdateSVNCode()
  340. {
  341. SwitchIntranet
  342. echo -e "\n\n==========执行函数:UpdateCode=========="
  343. # 本地APK SVN目录是否存在,存在则删除;
  344. if [ -d ${APK_SRC_DIR} ]; then
  345. echo -e "目录不为空,删除未提交的文件;\n"
  346. #rm -rf ${APK_SRC_DIR} # 删除操作太危险;
  347. svn cleanup ${APK_SRC_DIR}
  348. filelist=$(svn status ${APK_SRC_DIR} 2>&1)
  349. echo -e "未提交的文件="${filelist}
  350. # 以"A "分组字符串,并修改logo后缀;
  351. filearray=(${filelist//? /})
  352. for File in ${filearray[@]}
  353. do
  354. # 文件是否存在;
  355. if [ -f ${File} ];then
  356. rm -f ${File}
  357. echo -e "已删除文件=${File}\n"
  358. elif [ -d ${File} ];then
  359. rm -rf ${File}
  360. echo -e "已删除路径=${File}\n"
  361. fi
  362. done
  363. fi
  364. if [ x"${APK_SRC_URL}" = x ]; then
  365. echo -e "APK URL空\n"
  366. SwitchIntranet
  367. exit
  368. fi
  369. #echo -e "\t开始Check代码;\n"
  370. #svn co --force ${APK_SRC_URL} ${APK_SRC_DIR}
  371. echo -e "开始更新代码\n"
  372. svn_result=$(svn up ${APK_SRC_DIR} 2>&1)
  373. echo -e "UpdateCode: svn up结果=${svn_result}\n"
  374. if [[ $svn_result != *"At revision"* ]] && [[ $svn_result != *"Updated to revision"* ]]; then
  375. echo -e "连接SVN服务器失败, 网络异常!\n"
  376. SwitchIntranet
  377. exit
  378. fi
  379. cd ${APK_SRC_DIR}
  380. # 判断文件是否存在;
  381. if [ -f "update_modules.sh" ];then
  382. echo -e "\nupdate_modules.sh 文件存在,更新复用库\n\n"
  383. chmod 777 update_modules.sh
  384. ./update_modules.sh
  385. fi
  386. }
  387. UpdateGITCode()
  388. {
  389. SwitchIntranet
  390. echo -e "\n\n==========执行函数:UpdateCode=========="
  391. # 本地APK SVN目录是否存在,存在则删除;
  392. if [ -d ${APK_SRC_DIR} ]; then
  393. echo -e "目录不为空,删除未提交的文件;\n"
  394. cd ${APK_SRC_DIR}
  395. git clean -xfd
  396. fi
  397. if [ x"${APK_SRC_URL}" = x ]; then
  398. echo -e "APK URL空\n"
  399. SwitchIntranet
  400. #exit
  401. fi
  402. #echo -e "\t开始Check代码;\n"
  403. #svn co --force ${APK_SRC_URL} ${APK_SRC_DIR}
  404. echo -e "开始更新代码\n"
  405. git_result=$(git pull 2>&1)
  406. echo -e "UpdateCode: git pull结果=${git_result}\n"
  407. if [[ $git_result != *"files changed,"* ]] && [[ $git_result != *"Already up to date."* ]]; then
  408. echo -e "连接GIT服务器失败, 网络异常!\n"
  409. SwitchIntranet
  410. #exit
  411. fi
  412. cd ${APK_SRC_DIR}
  413. # 判断文件是否存在;
  414. if [ -f "update_modules.sh" ];then
  415. echo -e "\nupdate_modules.sh 文件存在,更新复用库\n\n"
  416. chmod 777 update_modules.sh
  417. ./update_modules.sh
  418. fi
  419. }
  420. compile()
  421. {
  422. echo ${CURR_TIME}
  423. echo "shell_log===>Compile start---------"
  424. # 判断工作副本是否需要更新;
  425. if [ x${REPO_TYPE} == 'xSVN' ];then
  426. IsUpdateSVN
  427. else
  428. IsUpdateGIT
  429. fi
  430. if [ $? == 1 ]
  431. then
  432. echo "需要更新代码"
  433. if [ x${REPO_TYPE} == 'xSVN' ];then
  434. UpdateSVNCode
  435. else
  436. UpdateGITCode
  437. fi
  438. cd ${WORK_HOME}/shell
  439. # 读取ini配置文件中的信息;
  440. releaseType=$(python3 -c 'import builder;print(builder.getReleaseName("'$APK_SRC_DIR'"))')
  441. if [ $releaseType == 'custom' ];then
  442. compileCustomApp
  443. else
  444. compileGeneralApp
  445. fi
  446. echo "shell_log===>Compile end------------"
  447. else
  448. echo "无需更新本地SVN"
  449. echo "shell_log===>No upgrade end------------"
  450. fi
  451. # 切换回内网;
  452. SwitchIntranet
  453. }
  454. main()
  455. {
  456. if [ $# -eq 1 ]; then
  457. REBUILD=1
  458. APK_SRC_DIR=$1
  459. elif [ $# -eq 2 ]; then
  460. APK_SRC_DIR=$1
  461. REBUILD=$2
  462. fi
  463. echo -e "########################################################开始编译########################################################\n"
  464. # 导出变量到子shell;
  465. export WORK_HOME #/home/data/ApkAutoCompile
  466. export GRADLE_HOME #/home/data/android/gradle/gradle-6.7.1
  467. export ANDROID_SDK_HOME #/home/data/android/android_sdk/android-sdk-linux
  468. # 创建 编译完成的Apk文件 根目录;
  469. if [ ! -d ${APK_ROOT_DIR} ];then
  470. mkdir -p ${APK_ROOT_DIR}
  471. fi
  472. # Apk Debug目录不用创建,但Release根目录需要;
  473. if [ ! -d ${APK_RELEASE_ROOT_DIR} ];then
  474. mkdir -p ${APK_RELEASE_ROOT_DIR}
  475. fi
  476. # 检出所有debug apk;
  477. if [ ! -d ${APK_DEBUG_ROOT_DIR} ];then
  478. svn co ${APK_DEBUG_ROOT_URL} ${APK_DEBUG_ROOT_DIR}
  479. fi
  480. # 检出中间件服务APK;
  481. if [ ! -d ${APK_DIR_TVMidware} ];then
  482. echo -e 'svn co TVMidware Apk'
  483. svn co https://odm-design-center-hz.tclking.com/svn/scbc_apps/trunk/TVMidware/debug/TVMidwareService ${APK_DIR_TVMidware}
  484. fi
  485. # 取右边第一个字符,判断是否为斜杠;
  486. if [ "${APK_SRC_DIR:0-1:1}" = "/" ];then
  487. # 若为斜杠,%号截取,删除右边第一个'/'及右边字符,保存左边字符;
  488. echo "最后为斜杠,删除斜杠"
  489. APK_SRC_DIR=${APK_SRC_DIR%/*}
  490. fi
  491. # 获取APK名称;
  492. APK_NAME=${APK_SRC_DIR##*/}
  493. echo -e "APK_SRC_DIR=${APK_SRC_DIR}\r\nAPK_NAME=${APK_NAME}"
  494. # 重新定义log文件;
  495. if [ ! -d /home/data/ApkAutoCompile/shell/log/gradlew/ ];then
  496. msg=$(mkdir /home/data/ApkAutoCompile/shell/log/gradlew/last)
  497. fi
  498. LOG_FILE="/home/data/ApkAutoCompile/shell/log/gradlew/${APK_NAME}.log"
  499. if [ -f ${LOG_FILE} ];then
  500. mkdir -p /home/data/ApkAutoCompile/shell/log/gradlew/last
  501. mv ${LOG_FILE} /home/data/ApkAutoCompile/shell/log/gradlew/last/${APK_NAME}.log
  502. fi
  503. if [ -d ${APK_SRC_DIR}/.git ];then
  504. REPO_TYPE='GIT'
  505. echo "-------仓库类型为GIT-------"
  506. else
  507. REPO_TYPE='SVN'
  508. echo "-------仓库类型为SVN-------"
  509. fi
  510. compile 2>&1 | tee ${LOG_FILE}
  511. echo -e "########################################################编译结束########################################################\n"
  512. }
  513. main $@