3

When using the immutables.io annotation processor in a multi-module android app, the build fails, when a package-info.java file is used.

I've managed to build a minimal test-project on GitHub to reproduce the issue: ImmutablesPackageInfoIssue

The project consists of 2 modules:

  • app: android application: @Value.Immutable is used in AndroidIm.java
  • lib: java module: @Value.Immutable is used in JavaIm.java

So basically, using immutables.io in both modules works fine.
But when we add a package-info.java file (to the com.example package in the app module), the compilation fails with this error:

com.android.build.api.transform.TransformException: 
com.android.dex.DexException: Multiple dex files define Lcom/example/ImmutableJavaIm$1;

The Dex error occurs, because ImmutableJavaIm.java is generated twice:

  • once in the lib project (expected):
    \build\generated\source\apt\main\com\example\ImmutableJavaIm.java
  • and ALSO in the app project (should not happen):
    \build\generated\source\apt\debug\com\example\ImmutableJavaIm.java

Known workarounds:

  • delete the package-info.java file
  • clear/comment out its contents
  • configure the build to ignore the package-info.java file

Note: I cannot just ignore the file, because it contains important annotations for the build: e.g. immutables-style configuration

Any ideas why this happens or what could be the cause?

TmTron
  • 17,012
  • 10
  • 94
  • 142
  • 2
    Sorry for pointless suggestion, but have you tried recreating the minimal project with Maven? This might help to narrow down the issue at least somewhat… Trying with an older version of Gradle/Android Gradle plugin might be helpful as well (I suspect a bug in those new dependency types). – user1643723 Jul 30 '17 at 05:44
  • @user1643723 thanks for the input. Actually I've managed to reproduce the issue in a plain java-project (without gradle) and I can also reproduce it with another annotation processor. I've asked another question which is more narrow: https://stackoverflow.com/questions/45412736/why-does-the-package-info-java-file-affect-annotation-processing – TmTron Jul 31 '17 at 09:58
  • You are most certainly onto something. It might be worthwhile to file an issue with javac, or ask on openjdk mailing lists. I have noticed, that both susceptible annotation processors use annotation with `RUNTIME` retention. Could that be relevant? Perhaps there is something like an extra pass, when package-info is present, and that pass might be triggering some sort of "binary code processing mode"… – user1643723 Jul 31 '17 at 12:50

0 Answers0