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:
- Copy
android-sdk/tools/proguard/examples/library.pro
toproguard-project.txt
in your library project. - Remove the sample input/output lines
-injars
,-outjars
,-libraryjars
,-printmapping
from the file. The Gradle build process automatically provides these options. - 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
Menuitem Tinting on Appcompat Toolbar
Circular Reveal Transition for New Activity
How to Import Set of Icons into Android Studio Project
How to Change Toolbar Home Icon Color
Is Gui for Android Sdk Manager Gone
Singleton with Parameter in Kotlin
Highlighting Text Color Using HTML.Fromhtml() in Android
How to Use Room Persistence Library with Pre-Populated Database
How to Align Android Toolbar Menu/Icons to the Left Like in Google Maps App
Starting Activity from Fragment Causes Nullpointerexception
Bulk Insertion on Android Device
How to Show a Marker in Maps Launched by Geo Uri Intent
Android Camera Android.Hardware.Camera Deprecated
Explain the Meaning of Span Flags Like Span_Exclusive_Exclusive
How to Show One Layout on Top of the Other Programmatically in My Case
Android in App Purchase: Signature Verification Failed
Adb Remount Permission Denied, But Able to Access Super User in Shell -- Android