Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未解析引用:转换为Kotlin后的DaggerAppComponent_Android_Kotlin_Import_Dagger 2 - Fatal编程技术网

Android 未解析引用:转换为Kotlin后的DaggerAppComponent

Android 未解析引用:转换为Kotlin后的DaggerAppComponent,android,kotlin,import,dagger-2,Android,Kotlin,Import,Dagger 2,我正在将一个旧的代码库从Java转换为Kotlin,但我正在努力实现Dagger组件。我尝试了多种解决方案和导入,但Android Studio拒绝识别DaggerAppComponent。这是我的AppController class AppController : Application() { var appComponent: AppComponent? = null private set override fun onCreate() { super.onCreat

我正在将一个旧的代码库从Java转换为Kotlin,但我正在努力实现Dagger组件。我尝试了多种解决方案和导入,但Android Studio拒绝识别DaggerAppComponent。这是我的AppController

class AppController : Application() {
var appComponent: AppComponent? = null
    private set

override fun onCreate() {
    super.onCreate()

    instance = this
    FacebookSdk.sdkInitialize(applicationContext)
    AppEventsLogger.activateApp(this)
    
    initRealmConfiguration()

    initDaggerComponent()

    initNewFonts()

}

private fun initRealmConfiguration() {
    Realm.init(this)
    val realmConfiguration = RealmConfiguration.Builder()
            .name(Realm.DEFAULT_REALM_NAME)
            .schemaVersion(1)
            .migration(MyMigrations())
            .deleteRealmIfMigrationNeeded()
            .build()
    Realm.setDefaultConfiguration(realmConfiguration)
}

private fun initDaggerComponent() {
   
    appComponent =  DaggerAppComponent.builder()
            .appModule(AppModule(this))
            .netModule(NetModule(BuildConfig.END_POINT))
            .build()
}

private fun initNewFonts() {
    ViewPump.init(ViewPump.builder()
            .addInterceptor(CalligraphyInterceptor(
                    CalligraphyConfig.Builder()
                            .setDefaultFontPath("fonts/Rosario-Italic.otf")
                            .setFontAttrId(R.attr.fontPath)
                            .build()))
            .build())
}

companion object {
    @get:Synchronized
    var instance: AppController? = null
        private set
}
}

这是我的AppComponent类:

@Singleton
@Module(includes = [AppModule::class, NetModule::class])
interface AppComponent {
    fun inject(activity: SplashActivity?)
    ***
    fun inject(dialogFragment: AddToPlannerDialogFragment?)
}
最后是我的进口:

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

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'com.google.dagger:dagger:2.27'
kapt "com.google.dagger:dagger-compiler:2.13"
implementation 'com.google.dagger:dagger-android:2.15'
implementation 'com.google.dagger:dagger-android-support:2.15'
kapt "com.google.dagger:dagger-android-processor:2.13"

您使用
@Module
注释定义组件不是一个问题吗

我认为您应该将AppComponent定义为
@组件
,如下所示:

@Singleton
@Component(modules = [AppModule::class, NetModule::class])
interface AppComponent {
  ...
}
此外,如果这不是解决方案,我建议仔细阅读构建输出,这通常有助于发现棘手的问题