简体   繁体   English

Android Dagger 2无法在Java / Kotlin项目中生成组件

[英]Android Dagger 2 not generating component in java/kotlin project

I really need your help as I can't proceed with my project. 我真的需要您的帮助,因为我无法继续进行我的项目。 The issue I am having is when I try to generate dagger component it seems not available. 我遇到的问题是,当我尝试生成匕首组件时,它似乎不可用。 I use java classes for Dagger component/module and Kotlin classes for the rest of application. 我将Java类用于Dagger组件/模块,将Kotlin类用于其余的应用程序。 I tried it with java only classes and it also doesnt work. 我只用Java类尝试过,它也不起作用。

Gradle : 摇篮

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

 android {
compileSdkVersion 26
  defaultConfig {
    applicationId "com.example.gebruiker.beertime1"
    minSdkVersion 15
    targetSdkVersion 26
    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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

implementation 'com.google.dagger:dagger-android:2.14'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.14'


implementation 'com.google.dagger:dagger:2.14'
annotationProcessor 'com.google.dagger:dagger-compiler:2.14'
kapt 'com.google.dagger:dagger-compiler:2.14'

implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
 }

My repository component : 我的存储库组件:

package com.example.gebruiker.beertime1.di;

 import com.example.gebruiker.beertime1.MainScreen.MainActivity;

  import javax.inject.Singleton;

  import dagger.Component;

  @Component(modules = NetworkModule.class)
  public interface RepositoryComponent {
   void inject(MainActivity mainActivity);
 }

My mainactivity component : 我的主要活动组件:

@Component(dependencies = RepositoryComponent.class ,modules = 
{AppModule.class,RepositoryModule.class,NetworkModule.class})
 interface MainActivityComponent{

void inject(MainActivity mainActivity);

 }

You're using annotationProcessor instead of kapt for some of your dependencies. 您正在使用annotationProcessor而不是kapt来处理某些依赖项。 Change your build.gradle to the following and it should work: 将您的build.gradle更改为以下内容,它应该可以工作:

def final dagger_version = '2.14.1'

implementation "com.google.dagger:dagger:${dagger_version}"
implementation "com.google.dagger:dagger-android:${dagger_version}"
implementation "com.google.dagger:dagger-android-support:${dagger_version}"
kapt "com.google.dagger:dagger-compiler:${dagger_version}"
kapt "com.google.dagger:dagger-android-processor:${dagger_version}"

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

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