Dagger2-未生成ApplicationComponent

时间:2018-10-22 09:07:13

标签: android module dagger-2 unresolved-external

我关注了有关vogella的文章:http://www.vogella.com/tutorials/Dagger/article.html

我按照他们的建议逐步进行了所有操作。我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "test.daggertest"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.dagger:dagger:2.15'
    implementation 'com.google.dagger:dagger-android:2.15'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.15'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.15'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

MyApplication类:

public class MyApplication extends Application implements HasActivityInjector
{
    @Inject
    DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;

    @Override
    public void onCreate()
    {
        super.onCreate();
        DaggerMyApplicationComponent.create().inject(this);
    }

    @Override
    public DispatchingAndroidInjector<Activity> activityInjector()
    {
        return dispatchingAndroidInjector;
    }
}

然后我做了Rebuild项目,但仍然引发错误DaggerMyApplicationComponent尚未解决。

我错过了什么或者他们的文章已经过时了吗?有什么想法吗?

0 个答案:

没有答案