android: register generated sources through the Variant API
Desktop (Tauri) / Windows installer (cross-compiled) (push) Successful in 2m16s
Android / Kotlin + Rust (debug APK) (push) Failing after 3m5s
Desktop (Tauri) / Tauri desktop (Linux) (push) Successful in 4m40s
Desktop (Tauri) / Update manifest (push) Successful in 5s

Second Android run failed with AGP 9 refusing the previous fix by name:

  You cannot add Provider instances to the Android SourceSet API. [...] Instead
  you should use the Sources interface in the Variant API, in particular
  SourceDirectories.addGeneratedDirectory

AGP cannot tell from a Provider whether the directory holds generated
(read-only) or hand-written (read-write) files, which is a distinction the IDE
needs. `addGeneratedSourceDirectory` is the supported route and — unlike the
plain-path form the error offers as an escape hatch — it carries the task
dependency, so Kotlin still cannot compile before the bindings are generated and
the APK cannot package a stale .so.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-18 15:43:57 -04:00
co-authored by Claude Opus 5
parent f179928c57
commit 3d3df1beb0
+17 -14
View File
@@ -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)