Is there a reasonably simple way for a module's build.gradle
file to indicate that certain files from a dependency should be excluded? I am specifically interested in excluding certain resources from an AAR.
LeakCanary is an interesting library for helping to track down memory leaks. However, it has an undocumented requirement of compileSdkVersion
of 21 or higher. While most projects should not have a problem with this, it's unseemly for a library to require a certain compileSdkVersion
without a good reason. A development team may have frozen their compileSdkVersion
as part of a general policy to only change those sorts of settings as part of major version updates of their app or something.
In this case, for v1.3.1 of LeakCanary at least, the only reason compileSdkVersion
is required, AFAICT, is because the AAR has a res/values-v21/
directory, containing a theme definition that inherits from Theme.Material
. This theme is used by a diagnostic activity. That activity is never seen by end users, only by developers in debug
builds. Frankly, what that activity looks like, theme-wise, does not really matter. Forcing a compileSdkVersion
of 21 just to have that diagnostic activity have a certain theme is, IMHO, stupid.
It'd be nice if as part of a compile
directive we could say "hey, please skip res/values-v21/
from this AAR, m'kay?". Since the -v21
theme is simply providing an alternative definition of a theme defined elsewhere, dropping the -v21
theme will not break the build or break things at runtime, but merely will give us a Holo
-themed diagnostic activity.
I fail to see how this answer works with dependencies. I am also uncertain if it is complete, and it certainly does not appear to be supported. It also doesn't really qualify as "simple" — I would not expect somebody to try dropping this in a build.gradle
file just to block a single file from a diagnostic library like LeakCanary.
So, is there something simpler than this that works with now-current editions of the Android Plugin for Gradle?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…