Launch Proguard in a multi-module project as a “one piece”,

TL; DR: how to pass proguard mapping to javac for compilation with obfuscation library?

This is long, but I don’t see how to make it shorter:

Background: I have the following product setup:

Android Studio project - Library module - (optional) Core module - (auxiliary) module A - (auxiliary) module B - (auxiliary) module C - Example application module -... Other modules

Each of the submodules of the A, B, C library of reference classes in Core, but A, B, C are independent of each other. Conceptually similar to Play Services, where the user can only have the code and the necessary submodule. Each of the submodules of the library has external APIs, but also many internal classes. The goal is to be able to distribute Core, A, B, C as independent aar-s.

Purpose: obfuscate all submodules together leaving only public APIs, but packages and distributing them separately in obfuscation / optimized form.

Question: I do not see how to use it with a simple gradle configuration. Do you need a custom build system here if there is no known solution?

What is needed here:

  • Java compiling all submodules together
  • Prologue-obfuscation them together.
  • Run all other build processes separately

Where is the normal assembly process for each module: - Compile → do everything, including. obfuscation → package

Direct tuning does not work when compiling the first submodule after Core. If it were possible to pass Proguard mapping.txt as input to the Java compiler ... But I could not find such an option. Any ideas?

Thanks!!!

+7
java android proguard android-proguard
source share
2 answers

I had the same problem and wrote this post on my personal site .

Essentially, you need the maven-publish Gradle plugin, which allows you to pack your library modules into AARs and conveniently manage and distribute them, storing information about their dependencies.

You can configure this plugin to package a specific buildType , for which you enable the obguuscation proguard function.

+1
source share

Problem: I do not see how to use it with a simple gradle configuration. Do you need a custom build system here if no known solution exists?

So you are looking for a “custom build system” since you do not know how to do this in gradle. But if this can be resolved in gradle, you would like to use it, right?

To reprogram the libraries with gradle, you have 2 options:

  • Run Proguard for each library independently . In each module, set minifyEnabled true and use the proguardFiles function to install the proguard.txt file.
  • Run Proguard only in your application module . In each module, set minifyEnabled false and use the consumerProguardFiles function to transfer the proguard.txt file from each library to the main module.

The code examples are explained in detail here, so I'm not going to replicate the answer: fooobar.com/questions/846532 / ...

+1
source share

All Articles