支持360自动加固task

作者: 陈桐Caliburn | 来源:发表于2019-02-25 15:51 被阅读167次

支持360自动加固task

执行命令


执行命令 gradle jiaguDebug

引用

apply from: "jiagu.gradle"

配置

def executeCmd(cmd){
    def jiaGuPluginPath = getJiaGuProperty()
    println "执行命令行:" + cmd
    println "jiagu.dir=" + getJiaGuProperty()
    def p = cmd.execute(null, new File(jiaGuPluginPath))
    println p.text
    p.waitFor()  // 用以等待外部进程调用结束
    println p.exitValue()
}

def getJiaGuProperty(){
    File file = rootProject.file('local.properties')
    if(file.exists()){
        //加载资源
        InputStream inputStream = rootProject.file('local.properties').newDataInputStream()
        Properties properties = new Properties()
        properties.load(inputStream)

        if (properties.containsKey("jiagu.dir")){
            return properties.getProperty("jiagu.dir")
        }else {
            println "请在local.properties 添加jiagu.dir 例子如下"
            println "jiagu.dir=/Users/chentong/Android/360jiagubao_mac/jiagu"
            return ""
        }
    }
}

task jiaguDebug(dependsOn: 'assembleDebug') {
    group "jiaguapk"
    doLast {
        jiagu("debug")
    }
}

task jiaguRelease(dependsOn: 'assembleRelease') {
    group "jiaguapk"
    doLast {
        jiagu("release")
    }
}

def jiagu(buildType){

    println "360加固--------begin---------"

    //获得apk路径
    def appFilePath = getAppFilePath(buildType)

    if (!new File(appFilePath).exists()) {
        println "apk not exist"
        return
    }

    def cmdBase = 'java -jar jiagu.jar'

    //获得加固宝输出路径
    def outPath = getJiaGuPath()

    File outFile = new File(outPath)
    if (!outFile.exists()){
        outFile.mkdirs()
    }

    def cmdJiaGu = cmdBase + ' -jiagu ' + appFilePath + ' ' + outPath + ' -autosign' + ' -automulpkg'

    executeCmd(cmdJiaGu)
    println "360加固--------end---------"
}

def getAppFilePath(buildType){
    // 生成的apk的路径
    def appFilePath = getRootDir().getAbsolutePath() + File.separator + "app" +
            File.separator + "build" + File.separator + "outputs" + File.separator + "apk" +File.separator + buildType + File.separator +
            "app-" + buildType + ".apk"
    println "appFilePath=" + appFilePath
    return appFilePath
}

def getJiaGuPath(){
    def outPath = getRootDir().getAbsolutePath() + File.separator + "app" + File.separator + "360jiagu"
    println "jiaguPath=" + outPath
    return outPath
}

//清理加固文件
tasks.whenTaskAdded { theTask ->
    if (theTask.name == "assembleRelease" | theTask.name == "assembleDebug") {
        theTask.dependsOn "cleanJiaguDir"
    }
}

task cleanJiaguDir {
    def jiaguPath = getJiaGuPath()
    new File(jiaguPath).deleteDir()
}

感谢月亮的后羿提出的问题
我的task命令的打印日志:可以看一下
https://www.jianshu.com/p/fb538da65d28

后续优化方向
https://www.githang.com/2019/01/23/jenkins-enhanced/

相关文章

  • 支持360自动加固task

    支持360自动加固task 执行命令 引用 配置 感谢月亮的后羿提出的问题我的task命令的打印日志:可以看一下h...

  • Groovy (二) groovy 加固插件

    使用类似360加固 思路,下载360加固,根据命令行help配置自动执行加固打包 插件实现过程 开发方式 Buil...

  • Android_手动打包

    本文目标 项目包含bugly的热修复+360加固+VasDolly多渠道打包,打出来的包既加固了支持热修复还支持多...

  • Android_360加固

    本文目标 使用360加固保来加固项目 步骤 一.下载360加固保[https://jiagu.360.cn/#/g...

  • Android Gradle 自动打包插件

    自动打包插件 debug 包 支持自动上传蒲公英、发送钉钉通知 release包 支持乐固加固、...

  • (2)Gradle自动360加固

    参考了该篇文章,给我的帮助很大,然后我基于该篇文章完善更加适合我的项目https://www.imliujun.c...

  • Android 数据安全

    代码混淆 & apk的加固 常用加固平台:爱加密、360加固、腾讯加固、梆梆加固 Android应用加固原理 网络...

  • Jenkins+Android自动打包续2:用360加固程序加固

    360加固保介绍,具体见其官方网站 360加固保 现在安卓APP为了代码安全,都要求在发布前先加固,可以自己写加固...

  • 安卓一些操作

    1. 安卓指令加签加固流程 加固360加固 适用于大部分腾讯相关市场如果在提交360加固后的包提示加固不完整,则再...

  • 360加固保加固apk并自动签名

    原文地址:http://www.xdowns.com/article/170/Article_5940.html ...

网友评论

    本文标题:支持360自动加固task

    本文链接:https://www.haomeiwen.com/subject/stsgyqtx.html