Immutables-library generates the same immutable cl

2019-05-29 03:56发布

问题:

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?