1

When I connect my own library to project, it doesn't optimize. So:

  1. In my lib, i turn on minifyEnabled:
apply plugin: 'com.android.library'
...
 debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
...
  1. In project I implement my lib implementation project(':somelib')

  2. In my project, i turn on minifyEnabled:

...
 debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
...
  1. After build project, my lib is not optimized. I check it using APK Analyzer first then I use R8 and after it. Also, I connect lib in over project, where it is not used at all. But after optimization count method increased because I implement unused lib.

Proguard contains a standard autogenerated proguard-android.txt file with rules for Parseble and for butterknife6. Proguard-rules.pro is empty.

// default proguard-android.txt file
...
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }

-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
-keep class **$$ViewInjector { *; }
-keepclassmembers class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

-keep class * implements android.os.Parcelable {
*;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}
crysis74
  • 11
  • 2

1 Answers1

0

The proguard-android.txt file has a -dontoptimize rule that prevents optimizations. They actually mention in that file:

Note that if you want to enable optimization, you cannot just include optimization flags in your own project configuration file; instead you will need to point to the "proguard-android-optimize.txt" file instead of this one from your project.properties file.

So just replace

getDefaultProguardFile('proguard-android.txt')

with

getDefaultProguardFile('proguard-android-optimize.txt')
Cruceo
  • 6,763
  • 2
  • 31
  • 52