Dani Diprana
02/28/2024, 9:05 AMIllegalStateException: KoinApplication has not been started
IllegalStateException: KoinApplication has not been started
at GlobalContext.protoOf.get_26vq(/Users/arno/workspace/koin-projects/koin/core/koin-core/src/jsMain/kotlin/org/koin/core/context/GlobalContext.kt:80)
at Component.getKoin_18vqwx(/Users/arno/workspace/koin-projects/koin/core/koin-core/src/commonMain/kotlin/org/koin/core/component/KoinComponent.kt:33)
at <global>.<unknown>(/Users/arno/workspace/koin-projects/koin/core/koin-core/src/commonMain/kotlin/org/koin/core/Koin.kt:35)
at UnsafeLazyImpl.protoOf.get_value_j01efc(/Users/vidio/Workspace/vidio-app/shared/build/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/util/Lazy.kt:81)
It's interesting. Does someone ever experience the same issue? If yes, how do you guys encounter the issue?
Thanks ~Jacob Ras
02/28/2024, 11:47 AMPedro Francisco de Sousa Neto
02/28/2024, 2:38 PM@Module
created and it getting only one of N dependencies created.
The @ComponentScan
is right. How can I debug, or check it? My pain here is a walkthrough to validate.Angga Ardinata
02/29/2024, 4:53 AMval ktorfitModule = module {
single<Ktorfit> {
ktorfit {
// my config
}
}
}
then i used the ktorfit singleton in my child/service module like this
single<AuthService> {
val ktorfit : Ktorfit = get()
ktorfit.create()
}
and it works and compiled without any issue .. but when i try to do with annotations
AppModule
@Module(includes = [ServiceAuthModule::class])
@ComponentScan("com.ft.ats")
class AppModule {
@Single
fun getKtorfit(): Ktorfit {
return ktorfit {
// my config
}
}
}
Service Module
@Module
@ComponentScan("com.ats")
class ServiceAuthModule {
@Single
fun authService(ktorfit: Ktorfit) : AuthService = ktorfit.create()
@Single
fun getRepository(service: AuthService) : AuthRepository = AuthRepositoryImpl(service)
}
now its not compiled ..
im using this method both with Hilt and koin dsl without annotations and it has no problem ..
what am i missing ?Jan
03/01/2024, 11:33 AMAnkit Kumar
03/06/2024, 1:47 AMparam.value
to access it
internal class LoginViewModel(
private val loginUserUseCase: Lazy<LoginUserUseCase>,
private val dispatcherProvider: Lazy<DispatcherProvider>
)
LoginViewModel(inject(), inject())
CMIIW, but if we keep non-lazy normal variables and do get()
, those are eagerly initialised?arnaud.giuliani
03/06/2024, 12:47 PMTrey
03/06/2024, 8:50 PM* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':shared:cinteropAppAuthIosArm64'.
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:38)
...
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':shared:iosArm64CInterop'.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.mapFailure(DefaultConfiguration.java:1711)
...
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find io.insert-koin:koin-compose:3.5.3.
Searched in the following locations:
- <https://dl.google.com/dl/android/maven2/io/insert-koin/koin-compose/3.5.3/koin-compose-3.5.3.pom>
- <https://repo.maven.apache.org/maven2/io/insert-koin/koin-compose/3.5.3/koin-compose-3.5.3.pom>
- <https://maven.pkg.jetbrains.space/public/p/compose/dev/io/insert-koin/koin-compose/3.5.3/koin-compose-3.5.3.pom>
Required by:
project :shared
Vedran
03/07/2024, 12:30 PMplugins {
kotlin("jvm")
id("org.jetbrains.compose")
kotlin("plugin.serialization") version "1.9.20"
id ("com.google.devtools.ksp") version "1.9.22-1.0.17"
}
and also inside dependencies:
// KOIN
implementation(platform("io.insert-koin:koin-bom:3.5.4-RC1"))
implementation("io.insert-koin:koin-core")
implementation("io.insert-koin:koin-compose")
implementation(platform("io.insert-koin:koin-annotations-bom:1.3.1"))
implementation("io.insert-koin:koin-annotations")
implementation("io.insert-koin:koin-ksp-compiler")
and :
ksp {
arg("KOIN_CONFIG_CHECK","true")
}
Im able to use annotations and create modules but I'm not able to startKoin:
import org.koin.ksp.generated.module
this import is not existing (unresolved reference)
and also when I try to access my module inside startCoin: MyModyle().module
.module does not existynsok
03/07/2024, 1:06 PMPedro Francisco de Sousa Neto
03/08/2024, 3:36 PM@Single
class Item1(
@InjectedParam private val xpto: MyClass, <<<<
)
@Single
class MyComponent(
@InjectedParam private val xpto: MyClass, <<<<
private val item1: Item1
)
https://insert-koin.io/docs/reference/koin-annotations/definitions#injected-parameters-with-injectedparamsegunfamisa
03/13/2024, 7:45 PMmodule A:
interface A
module B:
interface B
@Single(binds = [B])
internal class BImpl : B
@Module
@ComponentScan
class KoinModuleB
module C:
interface C
@Factory(binds = [C])
internal interface CImpl(val b: B, val a: A) : C
@Module
@ComponentScan
class KoinModuleC
app module:
class AImpl : A
@Module(includes = [KoinModuleB, KoinModuleC]
AppModule {
fun provideA(impl: A): A
}
The generated code properly registered the dependencies.
Unfortunately however, compilation fails in module C with a
Missing Definition type '<package a>.A' for '<package c>.C'. Fix your configuration to define type 'A'.
I think somehow, it tries to fulfill the dependencies in Gradle module C while I have defined the implementation in the app module.
Is there a way to go around this?mohamed rejeb
03/18/2024, 6:05 AMorg.koin.core.error.ClosedScopeException: Scope '_root_' is closed
It fails getting the voyager StateScreenModel
I'm starting and stopping koin correctly and I'not using koin-compose.Joel Denke
03/19/2024, 6:39 PMAdam Ahmed
03/20/2024, 3:14 PMCaused by j50.a: Could not create instance for '[Singleton:'gd0.h']'
at org.koin.core.error.InstanceCreationException.<init>(InstanceCreationException.java:23)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:57)
at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:46)
at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:55)
at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.java:53)
at org.koin.mp.KoinPlatformTools.synchronized(KoinPlatformTools.java:36)
at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:53)
at org.koin.core.registry.InstanceRegistry.createEagerInstances(InstanceRegistry.java:91)
at org.koin.core.registry.InstanceRegistry.createAllEagerInstances$koin_core(InstanceRegistry.java:62)
at org.koin.core.Koin.createEagerInstances(Koin.kt:330)
at org.koin.core.KoinApplication.createEagerInstances(KoinApplication.java:74)
at org.koin.core.context.GlobalContext.startKoin(GlobalContext.java:65)
at org.koin.core.context.DefaultContextExtKt.startKoin(DefaultContextExt.kt:40)
at com.package.Application.initKoin(TravelPerkApplication.kt:89)
at com.package.Application.onCreate(TravelPerkApplication.kt:81)
John O'Reilly
03/21/2024, 8:24 AMViewModel
now available (https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0-alpha03) does it make sense now to have Koin's viewModel
available in KMP code?Anmol Verma
03/22/2024, 7:02 AMFatal Exception: java.lang.NoSuchMethodError
No direct method <init>(Lorg/koin/core/definition/BeanDefinition;)V in class Lorg/koin/core/instance/SingleInstanceFactory; or its super classes (declaration of 'org.koin.core.instance.SingleInstanceFactory' appears in base.apk!classes6.dex)
Do we know what can lead to this ?arnaud.giuliani
03/22/2024, 2:23 PMDaniele Segato
03/29/2024, 3:37 PM@Module()
@ComponentScan("com.example.api")
class ApiModule
@Factory
class Api(
@InjectedParam
private val client: HttpClient,
)
// Application onCreate
startKoin {
modules(
ApiModule().module, // how do I inject the httpClient?
)
}
how do I inject the http client in there?Saher Al-Sous
04/02/2024, 8:31 AMcommonMain
to startKoin
.
This file contains the expect value that will return the SqlDriver
for each platform, and the needed implementation to communicate with the database from commonMain
.
expect val dbModule: Module
val repoModel = module {
single<DbRepository> {
DbRepository(get<SqlDriver>())
}
}
fun initKoin() = startKoin {
modules(
dbModule,
repoModel
)
}
I found out that each platform have an Issue, so I decided to focus on one platform at a time.
the problem of the Android platform is that you can't get the context needed for the AndroidSqliteDriver
.
actual val dbModule: Module = module {
single<SqlDriver> {
AndroidSqliteDriver(Kos.Schema, androidContext(), "Kos")
}
}
for Android, you need the context to initialize the driver, but you have no way to inject it. since I'm starting Koin from commonMain
, I couldn't find a way to get the android context from the Application
class. I tried this way:
class MyApp: Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidContext(this@MyApp)
}
}
}
also this way
class MyApp: Application() {
override fun onCreate() {
super.onCreate()
koinApplication {
androidContext(this@MyApp)
}
}
}
and even this way
class MyApp: Application() {
override fun onCreate() {
super.onCreate()
loadKoinModules(
module {
single { this@MyApp }
}
)
}
}
and I always get an error...
Caused by: org.koin.core.error.KoinAppAlreadyStartedException: A Koin Application has already been started
Caused by: org.koin.android.error.MissingAndroidContextException: Can't resolve Context instance. Please use androidContext() function in your KoinApplication configuration.how is it possible to get android context for SqlDelight driver within kmp using Koin?
arnaud.giuliani
04/02/2024, 11:42 AMarnaud.giuliani
04/05/2024, 8:58 AMarnaud.giuliani
04/05/2024, 8:59 AMabdelrahmanesam20000
04/06/2024, 11:03 PMBirgit L
04/08/2024, 11:49 AMorg.koin.core.error.KoinAppAlreadyStartedException: Trying to run new Koin Application whereas Koin is already started. Use 'KoinContext()' instead of check for any 'startKoin' usage.This can be reproduced by pressing back so the Activity goes into the background and is stopped, then returning to it. This crash has been discussed here before: https://kotlinlang.slack.com/archives/C67HDJZ2N/p1707810902616629 My solution to this for now is using an isolated context (docs), since I don't want to use platform specific solutions to starting koin from an application level, and having the koinApplication being created in an object prevents it from being recreated with the main composable, i.e. preventing the crash. Q1: Are there any downsides to this solution I should be aware of? Q2: Will there be an update to the docs or a bugfix so this crash does not happen anymore?
Petros
04/11/2024, 4:20 PMMark
04/15/2024, 1:05 PMKoin.getAll()
always a single new instance is returned (and none of the existing instances). Is this a bug, or is there another way to do this?Lukasz Kalnik
04/17/2024, 1:08 PMclass Scanner(val config: ScannerConfig)
class ScannerConfig(val activity: Activity)
I want to declare a Scanner
factory to be used in different Activities, but I don't want to manually create ScannerConfig
in every Activity separately. Is it possible?Stevekitkat
04/17/2024, 3:28 PMe: [ksp] --> Missing Definition type 'android.content.Context' for 'me.androidbox.data.local.imp.UserTokenLocalDataSourceImp'. Fix your configuration to define type 'Context'.
e: Error occurred in KSP, check log for detail
@Single
class UserTokenLocalDataSourceImp(context: Context) : UserTokenLocalDataSource {
companion object {
private const val TOKEN = "token"
private const val FILE_NAME = "secret_shared_prefs"
}
private val masterKeys = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
private val encryptedSharedPreferences =
EncryptedSharedPreferences.create(
FILE_NAME,
masterKeys,
context,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
override suspend fun saveUserToken(token: String) {
encryptedSharedPreferences.edit {
this.putString(TOKEN, token)
this.apply()
}
}
override suspend fun fetchUserToken(): String? {
return encryptedSharedPreferences.getString(TOKEN, null)
}
}
In my module I have the following:
@Module
@ComponentScan
class UserTokenLocalDataSourceModule {
@Single
fun provideUserTokenLocalDataSourceImp(): UserTokenLocalDataSource {
return UserTokenLocalDataSourceImp(androidContext())
}
}
I thought I could use the androidContext()
the same way we use the koin DSL, but I get the following androidContext() unresolved reference
In my application class I have the following:
startKoin {
androidLogger()
androidContext(this@BusbyTravelMateApplication)
modules(
UserTokenLocalDataSourceModule().module,
)
}
kspVersion = "1.9.23-1.0.20"
koinVersion = "3.5.3"
kspKoinVersion = "1.3.0"
Colton Idle
04/17/2024, 5:23 PM