android - Dagger2 生成的类突然从 Android Studio 中消失了

我已经在 Android Studio 中使用 Dagger2 几个月了,但今天它突然停止工作并给我以下错误

 error: cannot find symbol
        return Dagger_Injector.builder()
               ^

symbol:   variable Dagger_Injector
  location: class Initializer
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

这是失败的代码

@Singleton
@Component(modules = {TestService.class, ServiceFactory.class})
public interface Injector {

    public final static class Initializer {

        public static Injector init(ApplicationLoader app, boolean bypassVerification) {
            return Dagger_Injector.builder()
                    .testService(new TestService())
                    .serviceFactory(new ServiceFactory(app))
                    .build();
        }

    }

    void inject(ApplicationLoader obj);
}

这是我的毕业信息

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------

Build time:   2014-11-24 09:45:35 UTC
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a

Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
OS:           Mac OS X 10.10.2 x86_64

这是我的 build.gradle 的内容

apply plugin: 'com.android.application'
apply plugin: 'robolectric'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.0'

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 11
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'                
        }

    }

    productFlavors {
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        androidTest {
            setRoot('src/androidTest')
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    dexOptions {
        preDexLibraries = false
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

tasks.withType(Test) {
    include '**/*Test.class'
    exclude '**/espresso/**/*.class'

    // configure max heap size of the test JVM
    maxHeapSize = "2048m"
}

dependencies {
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    compile 'javax.servlet:javax.servlet-api:3.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/renderscript-v8.jar')
    compile files('libs/jsonic-1.2.0.jar')
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.google.android.gms:play-services:3.2'
    compile 'com.squareup.retrofit:retrofit:1.6.1'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'com.commonsware.cwac:merge:1.0.2'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.android.support:support-v4:20.0.0'
    compile 'io.nlopez.smartlocation:library:2.0.8'
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
    apt     'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
    compile 'org.glassfish:javax.annotation:10.0-b28'
    compile 'com.github.amlcurran.showcaseview:library:5.0.0'
    compile 'com.edmodo:cropper:1.0.1'
}

感谢任何帮助。

最佳答案

因此,由于某种原因,生成的组件类的名称中似乎不再有下划线。只需查看您的 build/generated/source/apt 文件夹,就会发现它确实以这种方式发生了变化。

通过将 Dagger_Injector 替换为 DaggerInjector 等来修复它。

https://stackoverflow.com/questions/29509014/

相关文章:

c++ - 在 CMake 中添加自定义构建步骤

build - 告诉 cmake 保持安静

.net - 无法解析主要引用,因为它是针对比当前目标框架更高版本的 .NET 框架构建的

maven - 在maven中构建模块时如何构建依赖项目

xcode - 如何在 Xcode 4 的运行脚本构建阶段中使用 sudo?

python - 使用 bitbake 在项目中加快构建时间的方法?

build - 我可以拥有同名的库和二进制文件吗?

build - Gradle:如何为需要相同 Activity 但具有不同意图过滤器的不同 buil

python - LLVM clang 的 CMake 构建失败并显示 "Unexpected fa

maven - 在 Jenkins 中设置 Maven 参数