使用 Koin 时发现接口 kotlin.time.TimeMark 错误

And*_*hko 5 android koin

我正在使用这样的教程。我像本教程中一样添加了自己的模块和 viemodel,仅更改了实现:

implementation "io.insert-koin:koin-core:3.0.2"
implementation "io.insert-koin:koin-android:3.0.2"
Run Code Online (Sandbox Code Playgroud)

代替:

implementation "org.koin:koin-android:2.0.1"
implementation 'org.koin:koin-androidx-viewmodel:2.0.1'
implementation 'org.koin:koin-androidx-scope:2.0.1'
Run Code Online (Sandbox Code Playgroud)

将它们注册到 App 类中:

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        startKoin {
            androidLogger(Level.DEBUG)
            androidContext(this@App)
            modules(listOf(repositoryModule, viewModelModule, retrofitModule, apiModule))
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但我收到这样的错误:

java.lang.IncompatibleClassChangeError: Found interface kotlin.time.TimeMark, but class was expected (declaration of 'kotlin.time.TimeMark' appears in /data/app/pkg-ptdpYgWwV-BVxpo5sVLPxg==/base.apk!classes15.dex)
Run Code Online (Sandbox Code Playgroud)

它指向这条线:

modules(listOf(repositoryModule, viewModelModule, retrofitModule, apiModule))
Run Code Online (Sandbox Code Playgroud)

我的模块如下:

val viewModelModule = module {
    viewModel {
        UserViewModel(get())
    }
}

val repositoryModule = module {
    single {
        UserRepository(get())
    }
}

val apiModule = module {
    fun provideUseApi(retrofit: Retrofit): GithubApi {
        return retrofit.create(GithubApi::class.java)
    }

    single { provideUseApi(get()) }
}

val retrofitModule = module {
    fun provideHttpClient(): OkHttpClient {
        val okHttpClientBuilder = OkHttpClient.Builder()

        return okHttpClientBuilder.build()
    }

    fun provideRetrofit(client: OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .baseUrl("https://api.github.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build()
    }

    single { provideHttpClient() }
    single { provideRetrofit(get()) }
}
Run Code Online (Sandbox Code Playgroud)

但我不使用的 TimeMark 有什么问题吗?

小智 6

我在 Koin 中遇到了同样的错误。它帮助我更换

startKoin {
        androidLogger(Level.DEBUG)
        androidContext(this@App)
        modules(listOf(repositoryModule, viewModelModule, retrofitModule, apiModule))
    }
Run Code Online (Sandbox Code Playgroud)

startKoin {
        androidLogger(Level.ERROR)
        androidContext(this@App)
        modules(listOf(repositoryModule, viewModelModule, retrofitModule, apiModule))
    }
Run Code Online (Sandbox Code Playgroud)

显然与图书馆存在某种冲突。