使用 proguard 进行批量混淆

Batch obfuscation with proguard

我需要混淆 jars 文件列表。这样做的最佳方法是什么?这个罐子有相互依赖性。我是否需要为每个 jar 编写单独的 proguard conf 文件并编写一个脚本来遍历它?或者已有更好的方法?

最后,我能够通过创建 gradle 任务来实现这一点

  • 安装最新的gradle

  • 创建目录并执行gradle init和select basic

  • 创建一个文本文件,其中指定要混淆的所有输入 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    
    }