使用Proguard进行批量混淆

问题描述

我需要混淆jar文件列表。这样做的最佳方法是什么?此罐具有相互依赖关系。我是否需要为每个jar编写单独的proguard conf文件并编写脚本以对其进行遍历?还是已有其他更好的方法

解决方法

最后,我可以通过创建gradle任务来实现这一目标

  • 安装最新的gradle

  • 创建目录并执行gradle init并选择基本

  • 创建一个文本文件,其中所有指定用于混淆的输入jar

  • 创建proguard.conf

  • 使用以下任务更新build.gradle。

    buildscript {
      repositories {
        mavenCentral()
      }
      dependencies {
        classpath 'net.sf.proguard:proguard-gradle:6.0.3'
        classpath 'net.sf.proguard:proguard-base:6.0.3'
      }
    }
    task proguard(type: proguard.gradle.ProGuardTask) {
     configuration 'proguard.conf'
     new File("${System.getProperty('user.dir')}/injars.txt").eachLine { file ->
          injars "${System.getProperty('user.dir')}/inputjars/${file}"
          outjars "${System.getProperty('user.dir')}/outputjars/${file}"
     }
    
     libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
     libraryjars "${System.getProperty('java.home')}/lib/jce.jar"
     libraryjars "${System.getProperty('user.dir')}/dependencies/"    //All the dependant libraries    
    }