Skip to content

Commit ea06782

Browse files
jamesarichclaude
andcommitted
fix(di): start AppFunctionStateSync from the Application, not createdAtStart
The google-flavor AppFunctionsModule registered AppFunctionStateSync with createdAtStart = true. Eager creation needs the androidContext binding and immediately spawns the prefs-observing sync coroutine — so any Koin graph built outside a running app failed with NoDefinitionFoundException for android.content.Context. That broke KoinVerificationTest.verifyTypedBootstrapLoadsModuleGraph (the typed koinApplication<AndroidKoinApp>() bootstrap instantiates eager singletons), failing the shard-app CI job on this branch. The definition is now a plain @single (the graph stays lazily constructible) and GoogleMeshUtilApplication.onCreate resolves it once after startKoin has bound androidContext — same production behavior, explicit instead of implicit. It was the repo's only createdAtStart. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: James Rich <james.a.rich@gmail.com>
1 parent 25cc141 commit ea06782

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

androidApp/src/google/kotlin/org/meshtastic/app/GoogleMeshUtilApplication.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.meshtastic.app
1818

1919
import androidx.appfunctions.service.AppFunctionConfiguration
2020
import org.koin.java.KoinJavaComponent.getKoin
21+
import org.meshtastic.app.ai.appfunctions.AppFunctionStateSync
2122
import org.meshtastic.app.ai.appfunctions.MeshtasticAppFunctions
2223

2324
/**
@@ -30,6 +31,14 @@ class GoogleMeshUtilApplication :
3031
MeshUtilApplication(),
3132
AppFunctionConfiguration.Provider {
3233

34+
override fun onCreate() {
35+
super.onCreate()
36+
// Start the AppFunctions enabled-state sync. Resolved here (after startKoin has bound
37+
// androidContext) rather than via createdAtStart so that Koin graphs built outside a
38+
// running app — verification tests, previews — stay lazily constructible.
39+
getKoin().get<AppFunctionStateSync>()
40+
}
41+
3342
override val appFunctionConfiguration: AppFunctionConfiguration
3443
get() =
3544
AppFunctionConfiguration.Builder()

androidApp/src/google/kotlin/org/meshtastic/app/di/AppFunctionsModule.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class AppFunctionsModule {
3232
@Single
3333
fun meshtasticAppFunctions(provider: AiFunctionProvider): MeshtasticAppFunctions = MeshtasticAppFunctions(provider)
3434

35-
@Single(createdAtStart = true)
35+
// NOT createdAtStart: eager creation needs the androidContext binding and spawns the sync
36+
// coroutine, which breaks (and is wrong for) any Koin graph built outside a running app —
37+
// e.g. KoinVerificationTest's typed-bootstrap check. GoogleMeshUtilApplication starts it
38+
// explicitly at app startup instead.
39+
@Single
3640
fun appFunctionStateSync(
3741
context: Context,
3842
prefs: AppFunctionsPrefs,

0 commit comments

Comments
 (0)