android {
、、、
//加入360加固任务Task
task reinforceAppTask(dependsOn: 'assembleRelease') {
group "jiaGuApk"
doLast {
def currFile = new File(".")
//生成的apk的路径
def appFilePath = "F:\\apk"
File apkDir = new File(appFilePath)
File[] channelDirs = apkDir.listFiles()
for (int i = 0; i < channelDirs.length; i++) {
File lastFile = channelDirs[i]
println "channelDir 的值:" + lastFile.toString()
if (!lastFile.name.endsWith(".apk")) {
continue
}
println "360加固 begin"
def cmdBase = 'java -jar jiagu.jar'
def cmdLogin = cmdBase + " -login ${rootProject.ext.jiaGuUserName} ${rootProject.ext.jiaGuPwd}"
println "360加固 登录命令::" + cmdLogin.toString()
// println "360加固 rootProject.ext.storeFile.getCanonicalPath():" + rootProject.ext.storeFile.toString()
// println "360加固 rootProject.ext.storeFile.storePassword:" + rootProject.ext.storePassword.toString()
// println "360加固 rootProject.ext.storeFile.keyAlias:" + rootProject.ext.keyAlias.toString()
// println "360加固 rootProject.ext.storeFile.keyPassword:" + rootProject.ext.keyPassword.toString()
//导入签名keystore信息
def cmdImportSign = cmdBase + ' -importsign ' + rootProject.ext.storeFile.toString() + ' ' + rootProject.ext.storePassword + ' ' + rootProject.ext.keyAlias + ' ' + rootProject.ext.keyPassword
println "360加固 导入签名keystore信息: " + cmdImportSign.toString()
// //查看当前签名keystore信息
// def cmdShowSign = cmdBase + ' -showsign'
//
// def cmdConfig = cmdBase + ' -config -x86'
// //查看当前加固增强服务配置
// def cmdShowConfig = cmdBase + ' -showconfig'
// //版本查询
// def cmdVersion = cmdBase + ' -version'
//输出目录这里设置为当前目录
def outPath = new File("F:\\apk\\outputs")
//应用加固
def cmdJiaGu = cmdBase + ' -jiagu ' + lastFile.getPath() + ' ' + outPath.getCanonicalPath() + ' -autosign' + ' -automulpkg'
println "360加固 应用加固命令: " + cmdImportSign.toString()
execute360JiaGuCmd(cmdLogin)
execute360JiaGuCmd(cmdImportSign)
execute360JiaGuCmd(cmdJiaGu)
println "360加固---------------------------------------------end"
}
}
}
tasks.whenTaskAdded { theTask ->
if (theTask.name == "assembleRelease") {
theTask.dependsOn "cleanOutputsDir"
}
}
task cleanOutputsDir {
def outputsPath = getBuildDir().getAbsolutePath() + File.separator + "outputs" + File.separator
println "delete outputsPath=" + outputsPath
new File(outputsPath).deleteDir()
}
、、、
}
def execute360JiaGuCmd(cmd) {
def p = cmd.execute(null, new File(rootProject.ext.jiaGuPluginPath))
println "execute360JiaGuCmd执行CMD命令:" + p.text
p.waitFor() // 用以等待外部进程调用结束
println "execute360JiaGuCmd执行CMD 命令:" + p.exitValue()
}