gpt4 book ai didi

java - Dagger : Cannot find symbol error in generated Component code for a Kotlin nested class

转载 作者:行者123 更新时间:2023-12-01 18:16:16 24 4
gpt4 key购买 nike

我正在尝试@Inject一个具有嵌套dataInnerOuter类。当 Inner 用作泛型类型时,dagger 生成的 Component 代码将嵌套类引用为 Outer$Inner

我想知道是否有一个注释(或其他方式)可以用来生成所需的格式(即Outer.Inner)。

引用代码:

// injected class
class Outer @Inject constructor(
private val repository: Repository
) : BaseOuter<Outer.Inner, Output> {

override fun invoke(input: Inner): Observable<Output> {
return repository.getOutput(input.id)
}

data class Inner(
val id: String
)

companion object {
const val NAMED = "OUTER"
}
}
// dagger module
@Named(Outer.NAMED)
@Provides
fun provideOuter(
factory: WrapperFactory<Outer.Inner, Output>,
outer: Outer
): WrappedOuter<Outer.Inner, Output> {
return factory.wrap(outer)
}
// target class where Outer is injected
class TargetClass @Inject constructor(
@Named(Outer.NAMED) val outer: WrappedOuter<Outer.Inner, Output>
)
// generated code in DaggerMainComponent
...
import some.package.name.Outer$Inner;
// error: cannot find symbol
// import some.package.name.Outer$Inner; // should be when Outer.Inner
// ^
// symbol: class Outer$Inner
// location: package some.package.name
...

Dagger:v2.26 与 Kotlin v1.3.61

这个问题也被追踪here .

最佳答案

    apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "dev.curlybraces.flowpro"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
enabled = true
}



}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

//ui
implementation project(':ui-feature-flow-list')
implementation project(':ui-feature-newflow-title')
implementation project(':ui-feature-newflow-step')
implementation project(':ui-feature-flow-selectnode')
implementation project(':ui-feature-flow-selectstep')
implementation project(':ui-feature-flow-step-list')
implementation project(':ui-feature-flow-step-details')

//ui lib
implementation project(":ui-lib-base")
implementation project(":ui-lib-di")
implementation project(":ui-lib-databinding-adapters")

//analytics
implementation project(":core-lib-analytics")
implementation project(":core-lib-analytics-impl")

//plugin
implementation project(":core-lib-plugin")
implementation project(":core-lib-plugin-impl")

//core
implementation project(":core-lib-usecase")
implementation project(":core-lib-usecase-common")

//app
implementation project(":app-di")

//domain
implementation project(':domain-feature-flow')
implementation project(':domain-models-flow')

//data
implementation project(':data-feature-flow')

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"

//dagger2
implementation "com.google.dagger:dagger:$dagger_version"
implementation "com.google.dagger:dagger-android:$dagger_version"
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
//dagger2 test
testImplementation "com.google.dagger:dagger:$dagger_version"
testImplementation "com.google.dagger:dagger-android:$dagger_version"
kaptTest "com.google.dagger:dagger-android-processor:$dagger_version"
kaptTest "com.google.dagger:dagger-compiler:$dagger_version"

// Constraint Layout
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"

// firebase
implementation 'com.google.firebase:firebase-analytics:17.2.2'

// leak canary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.core:core-ktx:$androidx_core_ktx_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

关于java - Dagger : Cannot find symbol error in generated Component code for a Kotlin nested class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60359233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com