admin管理员组文章数量:1634853
文章目录
- 0、前提
- 1、新建脚本:plug_360_jiagu.gradle
- 2、在app的build.gradle中引入脚本
- 3、在local.properties中配置签名和360信息
- 4、在Gradle面板中执行加固命令
- 5、问题总结
0、前提
1、下载并安装 360加固助手
2、注册好 360的账号信息
一键打包、加固原理:
1、自定义task:“assembleRelease360”,依赖于 “assembleRelease” (即:先打包、后加固)
2、在assembleRelease360任务中,指向 360加固助手的安装目录,执行相关的cmd命令;
- 登录360加固助手
- 导入签名信息
- 执行加固命令
1、新建脚本:plug_360_jiagu.gradle
def userName360 = ''
def password360 = ''
def softPath360 = ''
def keystoreFilepath = ''
def keystorePSW = ''
def keystoreAlias = ''
def keystoreAliasPSW = ''
def keyfile = file('temp')
//签名相关key
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
keystoreFilepath = properties.getProperty("keystorePath")
if (keystoreFilepath) {
keystorePSW = properties.getProperty("keystorePassword")
keystoreAlias = properties.getProperty("keystoreAlias")
keystoreAliasPSW = properties.getProperty("keystoreAliasPassword")
keyfile = file(keystoreFilepath)
}
//360加固相关key
userName360 = properties.getProperty("360.userName")
password360 = properties.getProperty("360.password")
softPath360 = properties.getProperty("360.packagePath")
task assembleRelease360(dependsOn: 'assembleRelease') {
group = "360JiaGu"
//360加固
// https://docs.gradle/current/javadoc/org/gradle/api/Project.html
doLast {
logInfo "=================== 360jiagu begin ==================="
def apkPath = getReleaseApkPath()//apk位置
def outputDirectory = getReleaseApkJiaguPath()//输出目录
if (!new File(apkPath).exists()) {
logError "apk not exist" + apkPath
return
}
def jiaguDir = new File(outputDirectory)
if (jiaguDir.exists()) {
jiaguDir.deleteDir()
}
new File(outputDirectory).mkdirs()
def cmdBase = "java.exe -jar $softPath360\\jiagu.jar"
def cmdLogin = cmdBase + " -login ${userName360} ${password360}"
def cmdImportsign = cmdBase + ' -importsign ' +
keyfile.getCanonicalPath() + ' ' +
keystorePSW + ' ' +
keystoreAlias + ' ' +
keystoreAliasPSW
def cmdShowSign = cmdBase + ' -showsign'
def cmdConfig = cmdBase + ' -config -x86'
def cmdShowConfig = cmdBase + ' -showconfig'
def cmdVersion = cmdBase + ' -version'
def cmdJiagu = cmdBase + " -jiagu $apkPath $outputDirectory -autosign"
logInfo '360加固登录中 cmdLogin'
execute360JiaguCmd(softPath360, cmdLogin)
logInfo '360加固导入签名 cmdImportsign'
execute360JiaguCmd(softPath360, cmdImportsign)
// logInfo '360加固配置 cmdConfig'
// execute360JiaguCmd(softPath360, cmdConfig)
logInfo '360加固开始加固 cmdJiagu'
execute360JiaguCmd(softPath360, cmdJiagu)
logInfo "=================== 360jiagu end ==================="
}
}
在task被添加的时候定义依赖关系
//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
// // 删除旧的apk
// new File(outputsPath).deleteDir()
//}
def getReleaseApkPath() {
def apkDir = getBuildDir().getAbsolutePath() + File.separator +
"outputs" + File.separator +
"apk" + File.separator +
"release"
def apkDirFile = new File(apkDir)
if (!apkDirFile.exists()) {
throw new RuntimeException("apk output path not exists:" + apkDir)
}
def apkPath = null
for (int i = apkDirFile.listFiles().length - 1; i >= 0; i--) {
File file = apkDirFile.listFiles()[i]
if (file.isFile() && file.name.endsWith(".apk")) {
apkPath = file.getPath()
break
}
}
println("apkPath = $apkPath")
return apkPath
}
def getReleaseApkJiaguPath() {
def apkJiaguDir = getBuildDir().getAbsolutePath() + File.separator +
"outputs" + File.separator +
"apk" + File.separator +
"release" + File.separator +
"jiaguOutput"
println("加固输出目录 = $apkJiaguDir")
return apkJiaguDir
}
def execute360JiaguCmd(String package360Path, String cmd) {
def file = new File(package360Path)
if (!file.exists()) {
logError "360 binPackagePath not exist " + package360Path
}
logInfo(cmd)
def p = cmd.execute(null, file)
logInfo p.text
p.waitFor() // 用以等待外部进程调用结束
logInfo p.exitValue()
}
def logInfo(text) {
println '【Info】' + text
}
def logError(text) {
println '【错误】' + text
}
2、在app的build.gradle中引入脚本
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
apply from: '../plug_360_jiagu.gradle'//引入360加固插件
3、在local.properties中配置签名和360信息
sdk.dir=C\:\\Android\\AndroidSDK
# 360加固保用户名
360.userName=***
# 360加固保登陆密码
360.password=***
# 加固保 安装的路劲
360.packagePath=D\:\\soft\\360jiagubao_windows_x64\\jiagu
## 签名信息
keystorePath=../***.jks
keystorePassword=***
keystoreAlias=***
keystoreAliasPassword=***
4、在Gradle面板中执行加固命令
点击“assembleRelease360”,自动 进行打包、加固。
加固完成后的apk:…/app/build/outputs/apk/release/jiaguOutput/***.apk
参考源码:JiaGuDemo
5、问题总结
1、根据实际情况,正确的指向360加固助手的安装位置,否则无法执行cmd命令;
2、根据控制台的打印信息、排查问题;
3、AS控制台日志乱码,借助 360加固助手查看错误信息;
问题:加固进度达到了100%,但是输出目录为空;错误信息又乱码了,无法排查:
解决:可以启动电脑端的 360加固助手.exe,登录进去后,查看错误信息:
4、免费加固次数限制规则:
1)未认证用户:可加固2次/天;
2)认证个人用户:可加固10次/天;
3)认证企业用户:可加固20次/天;
专业防篡改、高级防逆向、企业版加固服务用户及其他加固套餐用户,日加固次数不限。
5、官方 错误码常见问题
参考链接:
https://jiagu.360/#/global/index
https://yanwenjing.blog.csdn/article/details/108519491
https://blog.csdn/m0_37048188/article/details/82758584
本文标签: 一键脚本AndroidStudioGradle
版权声明:本文标题:AndroidStudio配置一键360加固gradle脚本 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729202863a1189792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论