Immutables-library generates the same immutable class twice

安稳与你 提交于 2019-12-22 11:33:47

问题


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?

来源:https://stackoverflow.com/questions/45393034/immutables-library-generates-the-same-immutable-class-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!