diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 656f307..ecf686c 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -187,25 +187,28 @@ android { compose = true } - sourceSets { - getByName("main") { - // The .so and the bindings are build outputs, not checked-in sources. - // Passing the TASK PROVIDERS, not plain paths: Gradle reads each - // task's @OutputDirectory and infers the build ordering itself. A - // bare path would compile Kotlin before the bindings exist, and the - // usual fix — depending on KotlinCompile by type — cannot be written - // here, because AGP 9's built-in Kotlin means that class is not on - // the buildscript classpath. - jniLibs.srcDir(cargoNdkDebug) - java.srcDir(generateBindings) - } - } - packaging { resources.excludes += "/META-INF/{AL2.0,LGPL2.1}" } } +/** + * Register the `.so` and the generated bindings as GENERATED sources. + * + * NOT `sourceSets { ... srcDir(task) }`: AGP 9 rejects a Provider there outright, + * because it cannot tell whether the directory holds generated (read-only) or + * hand-written (read-write) files — a distinction the IDE needs. The Variant API + * is the supported route and, unlike a bare path, `addGeneratedSourceDirectory` + * carries the task dependency, so Kotlin cannot compile before the bindings + * exist and the APK cannot package a stale `.so`. + */ +androidComponents { + onVariants { variant -> + variant.sources.kotlin?.addGeneratedSourceDirectory(generateBindings, UniffiBindgen::outputDir) + variant.sources.jniLibs?.addGeneratedSourceDirectory(cargoNdkDebug, CargoNdkBuild::jniLibsDir) + } +} + dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.activity.compose)