Jenkins之安卓打包-加固-上传蒲公英

1.基础环境

Android SDK r24(项目未设置NDK)
gradle 4.1-6.4(打包工具)
360加固账号
蒲公英账号
Jenkins已经部署安装好

2.配置编译打包步骤

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

在这里插入图片描述在这里插入图片描述注意:这里主要是修改build.gradle 配置和添加local.properties 文件到代码中,具体是根据项目情况来决定脚本:

	```bash
	#修改build.gradle配置和添加local.properties
	#cp -f /application/guominHealthy/app/build.gradle   $JENKINS_HOME/workspace/$JOB_NAME/app
	cp -f /application/guominHealthy/local.properties   $JENKINS_HOME/workspace/$JOB_NAME
	cd $JENKINS_HOME/workspace/$JOB_NAME
	sed -i "s/huawei {}//g" app/build.gradle
	sed -i "s/tuia {}//g" app/build.gradle
	sed -i "s/oppo {}//g" app/build.gradle
	sed -i "s/vivo {}//g" app/build.gradle
	sed -i "s/samsung {}//g" app/build.gradle
	sed -i "s/xiaomi {}//g" app/build.gradle
	sed -i "s/baidu {}//g" app/build.gradle
	sed -i "s/qihoo360 {}//g" app/build.gradle
	
	
	#修改生产特定配置信息为true
	str=`grep -n "buildConfigField" app/build.gradle|cut -d ":" -f 1`
	arr=(${str// /})
	num1=${arr[0]}
	num2=${arr[1]}
	prodconfig="buildConfigField \"boolean\", \"isLatest\", \"false\"  "
	sed -i "${num1}a ${prodconfig}" app/build.gradle 
	sed -i "${num2}a ${prodconfig}" app/build.gradle 
	
	sed -i "${num1}d" app/build.gradle 
	sed -i "${num2}d" app/build.gradle
	
	
	sed -i "s://storePassword 'gmjk_wjj_2018':storePassword 'gmjk_wjj_2018':" app/build.gradle
	sed -i "s://storeFile file('/application/gmjk.jks'):storeFile file('/application/gmjk.jks'):" app/build.gradle
	sed -i "s://keyAlias 'guomingjiankang':keyAlias 'guomingjiankang':" app/build.gradle
	sed -i "s://keyPassword 'gmjk_wjj_2018':keyPassword 'gmjk_wjj_2018':" app/build.gradle
	
	
	
	#替换不同环境的参数来实现打包
	cd $JENKINS_HOME/workspace/$JOB_NAME/common/src/main/java/com/project/common/core/utils
	num3=`grep -n "private String defaultIndex" UrlUtils.java|cut -d ":" -f 1`
	env="    private String defaultIndex = "\"$Environment\"";"
	sed -i "${num3}a ${env}" UrlUtils.java
	sed -i "${num3}d" UrlUtils.java
	
	
	#删除上次构建可能保存的多余apk
	cd $JENKINS_HOME/workspace/$JOB_NAME && rm -f app_*.apk
	echo "start git clone code....................................................................................."
	echo $TYPE
	echo $Version
	echo $Environment
	echo $UpDescription
	
	
	#修正权限防止jenkins用户没有执行权限
	sudo chown -R  jenkins.jenkins /application/androidsdk
	
	```

在这里插入图片描述注意:这里Jenkins要配置好gradle,才能进行选择。

在这里插入图片描述注意:这一步上传apk到蒲公英,然后钉钉提示

	```bash
	#test直接上传不加固
	echo $env
	echo $num
	
	mv $JENKINS_HOME/workspace/$JOB_NAME/app/build/outputs/apk/yingyongbao/release/app_${TYPE}_yingyongbao_*.apk   $JENKINS_HOME/workspace/$JOB_NAME/app/build/outputs/apk/app_${TYPE}_yingyongbao.apk
	curl -F  file=@$JENKINS_HOME/workspace/$JOB_NAME/app/build/outputs/apk/app_${TYPE}_yingyongbao.apk  -F   "uKey=xxxxxxx" -F "_api_key=xxxxxx" -F buildUpdateDescription=$UpDescription  -F "buildInstallType=2" -F "buildPassword=123456"   https://www.pgyer.com/apiv2/app/upload
	
	```

在这里插入图片描述

3.360加固安卓应用

在这里插入图片描述注意:加固需要jenkins所在服务器安装360加固软件Linux版本

```bash
#0.定义
#array_name=(yingyongbao qihoo360 huawei tuia oppo vivo samsung xiaomi baidu)
#array_name=(yingyongbao baidu)
array_name=(yingyongbao huawei)
#1.清空历史包
cd ${JENKINS_HOME}/workspace/${JOB_NAME} && rm -f *.apk


#2.循环加固已经打包后的apk
mkdir ${JENKINS_HOME}/workspace/$JOB_NAME -p
cd /application/360jiagubao_linux_64/jiagu
for app in ${array_name[*]};
do
echo $app
mv ${JENKINS_HOME}/workspace/android-prod/app/build/outputs/apk/app_${TYPE}_${app}*.apk   ${JENKINS_HOME}/workspace/android-prod/app/build/outputs/apk/app_${TYPE}_${app}.apk
java/bin/java -jar jiagu.jar -jiagu  ${JENKINS_HOME}/workspace/android-prod/app/build/outputs/apk/app_${TYPE}_${app}.apk  ${JENKINS_HOME}/workspace/$JOB_NAME  -autosign -pkgparam /application/360jiagubao_linux_64/jiagu/template_android.txt
#java/bin/java -jar jiagu.jar -jiagu  ${JENKINS_HOME}/workspace/android-prod/app/build/outputs/apk/app_${TYPE}_${app}_*.apk  ${JENKINS_HOME}/workspace/$JOB_NAME  -autosign -pkgparam /application/360jiagubao_linux_64/jiagu/template_android.txt
done

echo "jiagu  success!download:${JENKINS_HOME}/workspace/$JOB_NAME》》》》》》》》》》》》》》》》》》》》》》》》》》"

```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值