简体   繁体   English

无法解析生成的类

[英]Unable to resolve generated classes

I'm using Dagger 2 with Gradle and have everything setup and code generation is working properly. 我将Dagger 2与Gradle结合使用,并且所有设置和代码生成均正常工作。

My build.gradle: 我的build.gradle:

task wrapper(type: Wrapper) {
    gradleVersion = '2.11'
}

subprojects {
    apply plugin: 'java'

    repositories {
        mavenCentral()
    }

    dependencies {
        ... omitted as irrelevant to question ...

        compile 'com.google.dagger:dagger:2.0.2'
        compile 'com.google.dagger:dagger-compiler:2.0.2'
        compile 'javax.inject:javax.inject:1'
    }

}

My problem is that I am unable to resolve the classes and use them in my source, any solutions I've found are targeted towards Android which I am not using. 我的问题是我无法解析这些类并在我的源代码中使用它们,我发现的所有解决方案都针对我未使用的Android。 How would I be able to resolve these generated classes as dependencies? 如何将这些生成的类解析为依赖项?

I had a similar issue some time ago. 我前段时间也遇到过类似的问题。 In your case I would say that you need the apt plugin. 在您的情况下,我会说您需要apt插件。 Check this question where I explained how I resolved it 在我解释了解决方法的地方检查此问题

I fixed this issue by enabled annotation processing in my IDE as well as adding Dr. Pelocho's answer. 我通过在IDE中启用注释处理以及添加Pelocho博士的答案来解决此问题。

  • Apply this answer: https://stackoverflow.com/a/33445767/1787084 to your build.gradle 将以下答案应用到您的build.gradle: https ://stackoverflow.com/a/33445767/1787084

  • Add apply plugin: 'eclipse' in your build.gradle 在build.gradle中添加Apply apply plugin: 'eclipse'

  • Enable annotation processing to the apt directory created by the ltgt gradle apt plugin in Eclipse by navigating to project properties -> Java compiler -> Annotation processing -> Enable project specific settings -> Enable annotation processing 通过导航到项目属性-> Java编译器->批注处理->启用项目特定设置->启用批注处理,启用对Eclipse中ltgt gradle apt插件创建的apt目录的批注处理。

  • Change generated source directory to build/generated/source/apt/main to match the ltgt default directory 将生成的源目录更改为build/generated/source/apt/main generation build/generated/source/apt/main以匹配ltgt默认目录

  • Click "OK" or "Apply" 点击“确定”或“应用”

This added the Dagger generated classes to my build path and classpath 这将Dagger生成的类添加到我的构建路径和classpath中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM