4

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.

Trevor A.
  • 278
  • 3
  • 11

2 Answers2

1
// Auto factory for Assisted Injection
annotationProcessor "com.google.auto.factory:auto-factory:${libs.autoFactoryVersion}"
provided "com.google.auto.factory:auto-factory:${libs.autoFactoryVersion}"
  • This does not appear to solve the problem. It is complicated by the fact that we recently upgraded to Android Studio 3.0 with the Android 3.0.0 Gradle plugin and Gradle 4.1. – Trevor A. Nov 13 '17 at 18:06
  • We were already trying with "provided" rather than "compile," but that did not make a difference for ProGuard. To be clear, our problem is not using the AutoFactory annotation processor but configuring ProGuard to ignore its dependencies when creating release builds. – Trevor A. Nov 14 '17 at 15:04
1

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.

Trevor A.
  • 278
  • 3
  • 11