1

Getting a really strange issue; hopefully you guys can help.

I have been using Immutables library in my android project since a long time and had no issues. The auto-generated files for Immutable objects are located in (as example) build/generated/source/apt/debug/com/package/name/ImmutableClass.java and the project compiles and works fine.

I recently decided to use Dependency Injection in the same project and started using Dagger 2. I have used Guice in another Java project (non-Android), but never used Dagger before. All of a sudden, I am starting to get weird errors saying that the Immutables class could not be found.

Error: error: cannot find symbol class ImmutableClass.

I tried removing the @Component and @Module that I created and the errors went away. The funny thing is that the file ImmutableClass.java is still there in the same location as earlier.

Please let me know your thoughts. Thanks.

4

2 回答 2

2

当与其他代码生成库结合使用时,Dagger 2 确实会产生奇怪的错误消息。

如果您更深入地查看错误,那么您可能会发现另一个错误,上面写着“找不到符号类 DaggerXXXComponent”(或类似的东西)。

你很可能有一些问题导致 Dagger 预处理器失败。然后,由于 Dagger 失败,其他代码生成器将无法运行,包括 Immutables。

您需要调试导致 Dagger 失败的错误,然后 Immutables 错误也会消失。

于 2018-09-03T08:02:27.073 回答
0

请考虑<annotationÅrocessorPath>使用情况。通过编辑引用我当前模块的 pom.xml 文件,以下方法对我有用:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.immutables</groupId>
                        <artifactId>value</artifactId>
                        <version>${dependency.version.immutables}</version>
                    </path>
                    <path>
                        <groupId>com.google.dagger</groupId>
                        <artifactId>dagger-compiler</artifactId>
                        <version>2.16</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>

重要的是要提到:路径的排序顺序无关紧要。我正在使用 Maven 版本 3.6.0。

于 2020-02-17T10:48:07.440 回答