Proguard Ignores Config File of Library

Proguard ignores config file of library

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/library.pro 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.

Proguard : ignore library proguard errors

I finally came to a solution concerning proguard-android-optimize.txt.

In AndroidStudio, you have access to proguard-android-optimize.txt (⌘↑O on mac, or control + shift + N for windows/linux). Just copy the file content, and paste it to your project without the rules you want to remove. Finally use it as your own proguardFiles.

replace

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

with

proguardFiles 'proguard-android-optimize.txt', 'proguard-rules.pro'

Be aware that it is at your own risk and that you won't have the optimization from the latest embedded proguard files.

Concerning the consumerProguardFiles you have no choice to do pull request to them if you can, or ask for an evolve if you can contact the library author.

proguard doesnt ignore referenced libraries

As you have tried, you should put this single line in proguard-project.txt:

-dontwarn com.google.ads.**

You do have to make sure that ProGuard is actually using this configuration file, with this line in project.properties:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

This is the standard line for Android SDK r20 or higher (older versions used just proguard.config=proguard.cfg, in which case you had to specify the entire configuration, instead of relying on the one in the SDK).

Proguard won't include a library

As they mentioned in their doc,
You should put these lines in your proguard-rules.pro:

-keepclasseswithmembers class **.R$* {
public static final int define_*;
}
-keep class .R
-keep class **.R$* {
<fields>;
}

How to include a proguard configuration in my Android library (AAR)

In your Gradle file's default configuration closure, specify your Proguard file with consumerProguardFiles instead of proguardFiles. For example:

defaultConfig {
consumerProguardFiles 'proguard.txt'
}


Related Topics



Leave a reply



Submit