Marian Klühspies Marian Klühspies - 1 year ago 88
Android Question

Proguard ignores config file of library

I'm facing a really weird problem for days now...

I have an Gradle app with two modules, one main module and one library module.

  • In both modules I have declared a file path which is correct

  • In both .gradle files I have minifyEnabled true

here is the first problem: even if minifyEnabled is false in the library, it gets obfuscated. it has no effect at all and seems to depend on the main module's settings. I´m using proguard since a while now and I've never experienced such a behavior at all.

Also, the of the library seems to be completely ignored. It doesn't matter what I declare there, it is not used and the result is always the same (always decompiled to view result). It's obfuscated with the default settings.

I've used an invalid proguard file name to see if the file is even touched, and indeed there are errors with the wrong name and it also complaines about syntax errors in the proguard file...

I don't know if it is somehow related to an update of Android Studio, as it has also recommended me to use "minifyEnabled" instead of "runProguard".

How can I manage proguard to use the of the library too?


I've made an sample project to clarify my problem

enter image description here

The proguard config of my library

enter image description here

The gradle of my library:

enter image description here

And finally the result I always get. It doesn't matter what I exclude/include in the proguard config

enter image description here

As you can see, the proguard rules work quite well on the main module. It does what it should. But it always fully obfuscates my library to a.a....

It also has completely deleted the Activity of the Library, which shouldn't happen at all

Answer Source

You typically should not enable ProGuard in the library project. ProGuard processes the application and the library together in the application project, which is the most effective approach.

In the library project, you can specify any library-specific ProGuard configuration in build.gradle, e.g.:

defaultConfig {
    consumerProguardFiles 'proguard-rules.txt'

This file is then packaged in the library aar as proguard.txt and automatically applied in the application project.

If you do enable ProGuard in a library project (maybe because you want to distribute the library), then you also have to add the proper configuration for processing the library. The Android Gradle build doesn't seem to do this automatically. You can:

  1. Copy android-sdk/tools/proguard/examples/ to proguard-project.txt in your library project.
  2. Remove the sample input/output lines -injars, -outjars, -libraryjars, -printmapping from the file. The Gradle build process automatically provides these options.
  3. Reference the configuration from the build.gradle of the library project.

Enabling/disabling ProGuard independently for the library project and for the application project works fine for me.