How to exclude an annotation processor dependency from ProGuard

1.7k views Asked by At

I received a ProGuard warning when attempting to create a release of my Android project that prevents the build from completing successfully.

Warning: library class com.google.googlejavaformat.java.filer.FormattingJavaFileObject$1$1 extends or implements program class com.google.common.io.CharSink

After a little digging and running gradlew :app:dependencies, I discovered that google-java-format has been included because it is used by AutoFactory, which was recently added to the project.

+--- com.google.auto.factory:auto-factory:1.0-beta5
|    +--- com.google.auto:auto-common:0.6 (*)
|    +--- com.google.auto.value:auto-value:1.1 -> 1.3
|    +--- com.google.googlejavaformat:google-java-format:1.1

AutoFactory is only included in my build.gradle file as an annotationProcessor, so I don't understand why it is even being processed by ProGuard.

provided "com.google.auto.factory:auto-factory:1.0-beta5"
annotationProcessor "com.google.auto.factory:auto-factory:1.0-beta5"

I tried adding a -dontwarn com.google.gooogleformat.** to my ProGuard configuration file figuring that the library is only used during code generation and isn't actually required for the release. This had no effect.

I also looked at the online help, but I'm not clear on how to specify this dependency as a -libraryjars file as suggested.

How do I configure the app's ProGuard configuration file or its build.gradle file to prevent ProGuard from choking on this library? If it matters, I'm simply using ProGuard to remove unused code and not performing any obfuscation.

2

There are 2 answers

0
Trevor A. On BEST ANSWER

We revisited this issue after upgrading to Android Studio 3.0 with the Android 3.0.0 Gradle plugin and Gradle 4.1. It now appears that adding the following to proguard-rules.pro resolves the problem:

-dontwarn com.google.googlejavaformat.**
-dontwarn com.google.common.**

Looking at my original question, it appears that we likely mistyped the namespace for com.google.googlejavaformat when originally trying to solve this problem.

2
user1820178 On
// Auto factory for Assisted Injection
annotationProcessor "com.google.auto.factory:auto-factory:${libs.autoFactoryVersion}"
provided "com.google.auto.factory:auto-factory:${libs.autoFactoryVersion}"