I have an Android project with a proguard-rules.pro
file for the app
module that contains only the following:
# ProGuard rules
-dontobfuscate
-dontwarn android.arch.util.paging.CountedDataSource
-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource
I am not keeping anything myself. All -keep
rules are coming from something else, whether that is the rules provided by getDefaultProguardFile('proguard-android-optimize.txt')
or from rules packaged in libraries.
However, stuff is being kept that I am not using. If I use the Android Studio APK Analyzer on my release
build, while lots of things are removed by ProGuard, lots of other things are kept that I am not referencing.
For example: through transitive dependencies, I have the Support Library module that contains ViewPager
in the app's dependencies tree. However, I am not (presently) using ViewPager
in this app. Despite this, something is causing it to be kept, as the APK Analyzer shows 107 defined methods for android.support.v4.view.ViewPager
, including its constructor.
I could use various ProGuard options to track down why this is being kept. However, it is not coming from my rules. There is no -keep
of my own that needs fixing — the -keep
is coming from somebody else, presumably a Google engineer.
So, how do I get rid of ViewPager
? Is there a way that I can override the -keep
rule that is causing it to be kept (e.g., using allowshrinking
)? If so, how does ProGuard, as invoked by Android Studio, determine whose -keep
rule wins?