簡體   English   中英

DaggerAppComponent-未解決的參考

[英]DaggerAppComponent - unresolved reference

請幫助我將Dagger 2連接到Kotlin。 我的應用程序構建gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "mobile.socialboards.com"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 19
        versionName '1.0'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
        }
    }
    configurations {
        cleanedAnnotations
        compile.exclude group: 'org.jetbrains' , module:'annotations'
    }
    productFlavors {}
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs = ['-Xjvm-default=enable']
    }
    lintOptions {
        abortOnError false
    }
}

kapt {
    generateStubs = true
}

dependencies {
    ...

    implementation 'com.google.dagger:dagger-android:2.14.1'
    implementation 'com.google.dagger:dagger-android-support:2.14.1' // if you use the support libraries
    implementation "com.google.dagger:dagger:2.14.1"
    kapt 'com.google.dagger:dagger-android-processor:2.12'
    kapt "com.google.dagger:dagger-compiler:2.14.1"
    compileOnly "org.glassfish:javax.annotation:3.1.1"
}

apply plugin: 'com.google.gms.google-services'

我先做sуnc,然后重建,但是

DaggerAppComponent

Android Studio在我的Application kotlin類中找不到。 我研究了很多文章-仍然不明白有什么問題。 請幫忙!

我已經實現了完整的MVVM(Rx,Dagger,Kotlin),而匕首只需要這兩個:

 implementation 'com.google.dagger:dagger:2.12'
kapt 'com.google.dagger:dagger-compiler:2.12'

如果有什么讓我知道的!

非常簡單,您需要創建ApplicationComponent ,如下所示:

@Singleton
@Component(modules = [
    ApplicationModule::class,
])
interface ApplicationComponent {

    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: Application): Builder
           fun build(): ApplicationComponent
        }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM