步骤
2.project bulid.gradle : (配置需要用户路径和常量)
ext{
jiagubaoPath = 'D:\\AndroidTools\\360jiagubao_windows_64\\jiagu' // 加固保安装的路劲
storeFile = file('../xxx.jks') // 签名文件位置
storePassword = 'xxx' // 密码
keyAlias = 'xxx' // app别名
keyPassword = 'xxx' // key密码
jiaGu_UserName = 'xxx' // 360加固保用户名
jiaGu_Pwd = 'xxx' // 360加固保登录密码
}
3.app bulid.gradle
android {
.... //省略无用代码
task reinforceApkTask(dependsOn: 'assembleRelease') {
group "startJiaGuApk"
doLast {
println "360加固---------------------------------------------begin"
def currFile = new File(".")
// 生成的apk的路径,自己根据情况设定
def appFilePath = currFile.getCanonicalPath() +
File.separator + "app" + File.separator + "build"+ File.separator + "outputs" + File.separator +
"apk"+ File.separator +"release"+ File.separator+
"app-release-unsigned.apk";
println "APPPath=" + appFilePath
if(!new File(appFilePath).exists()){
println "apk not exist , please check it"
return
}
//下面是360加固API的命令操作
def cmdBase = 'java -jar jiagu.jar'
def cmdLogin = cmdBase + " -login ${rootProject.jiaGu_UserName} ${rootProject.jiaGu_Pwd}"
def cmdImportSign = cmdBase + ' -importsign ' +
rootProject.storeFile.getCanonicalPath() + ' ' + rootProject.storePassword + ' ' + rootProject.keyAlias + ' ' + rootProject.keyPassword
def cmdShowSign = cmdBase + ' -showsign'
def cmdConfig = cmdBase + ' -config -x86'
def cmdShowConfig = cmdBase + ' -showconfig'
def cmdVersion = cmdBase + ' -version'
def outPath = new File('..') //输出目录这里设置为当前目录
def cmdJiaGu = cmdBase + ' -jiagu ' + appFilePath + ' ' + outPath.getCanonicalPath() + ' -autosign' +' -automulpkg'
execute360JiaGuCmd(cmdLogin)
execute360JiaGuCmd(cmdImportSign)
executeJiaGu(cmdJiaGu)
println "360加固---------------------------------------------end"
}
}
}
//下面这段不在Android{}中
def executeJiaGu(cmd){
def p = cmd.execute(null, new File("$rootProject.jiagubaoPath "))
println p.text
p.waitFor() // 用以等待外部进程调用结束
println p.exitValue()
}
4.启动加固Task