2016-11-18 53 views
2

如标题所示,Dagger2不生成Dagger *前缀类。我看了一些其他类似的帖子,但似乎没有任何工作。Dagger2不生成匕首*类

我克隆此回购https://github.com/ecgreb/mvpc,已失效Android Studio中的缓存和重新启动它,我删除$Project/.gradle$Home/.gradle/caches,清理和重建项目,但仍不能工作。

这也发生在正在使用Dagger2

我缺少的东西一些项目?

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

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.3" 

    defaultConfig { 
    applicationId "com.example.ecgreb.mvpc" 
    minSdkVersion 15 
    targetSdkVersion 24 
    versionCode 1 
    versionName "1.0" 
    } 
    buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
    } 
} 

tasks.withType(Test) { 
    testLogging { 
    exceptionFormat "full" 
    events "started", "skipped", "passed", "failed" 
    showStandardStreams true 
    } 
} 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    compile 'com.android.support:design:24.2.1' 

    compile "com.google.dagger:dagger:2.7" 
    annotationProcessor "com.google.dagger:dagger-compiler:2.7" 
    provided 'javax.annotation:jsr250-api:1.0' 

    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.10.19' 
    testCompile 'org.assertj:assertj-core:1.7.1' 
    testCompile 'org.robolectric:robolectric:3.1.2' 
    testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1' 
} 

Application类。

package com.example.ecgreb.mvpc; 

import android.app.Application; 

import com.example.ecgreb.mvpc.controller.LoginActivity; 

import javax.inject.Singleton; 

import dagger.Component; 
public class MvpcApplication extends Application { 

    @Singleton @Component(modules = { LoginModule.class }) public interface ApplicationComponent { 
    void inject(LoginActivity loginActivity); 
    } 

    private ApplicationComponent component; 

    @Override public void onCreate() { 
    super.onCreate(); 
    //DaggerApplicationComponent IS NOT BEING GENERATED 
    component = DaggerApplicationComponent.builder().build(); 
    } 

    public ApplicationComponent component() { 
    return component; 
    } 
} 
+0

你能分享你的ApplicationComponent类 – AJay

+0

https://github.com/antoniolg/androidmvp你可以在这里看到整个代码。 @AJay – Bri6ko

+0

这个回购没有'匕首'代码。它唯一的mvp – AJay

回答

13

如果使用

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

然后代替

annotationProcessor "com.google.dagger:dagger-compiler:2.7" 

apt "com.google.dagger:dagger-compiler:2.7" 

Android的易不会在上班3.0,所以你需要annotationProcessor来代替每个apt

+0

工作。但是在设置指南https://github.com/google/dagger中,他们使用'annotaionProccessor'。此外,生成的类名是'DaggerMvpcApplication_ApplicationComponent'我认为他们不赞成这个约定,它不应该是'DaggerApplicationComponent'吗? – Bri6ko

+2

这个类的名称发生是因为你的接口是一个“内部类”('public static interface') – EpicPandaForce

+0

这很有道理。 – Bri6ko

0

对于任何在您的项目中使用Jack Compiler时遇到此类问题的人,您可能已经看到没有任何解决方案可行,原因与Dagger2本身相关。最新版本不适合杰克,我的经理直到2.2版本的Dagger2才开始工作。

+0

我也面临同样的问题。你是如何解决它的? http://imgur.com/a/9uOxX –

+0

我在Gradle依赖关系中坚持使用Dagger2的旧版本2.2来解决它。如果你想用Jack作为Dagger的编译器,那么现在就没有别的选择了。 –

+0

我在Java 8上使用2.2与Jack编译器,它根本不起作用。 –