From ffb235829e12fe6c0d51b530fa4dabc574a33a66 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sun, 8 Nov 2026 17:01:24 -0300 Subject: [PATCH 1/2] fix(build): declare buildMetadata class inputs for the selected build type buildMetadata registered the compiled-class directories as inputs only if they already existed at configuration time. Its outputs live in app/src/main/assets/metadata, outside build/, so after `rm -rf app/build` the task had no class inputs, was considered UP-TO-DATE and was skipped: the APK shipped stale metadata and newly added Java/Kotlin classes were undefined from JS. It also declared the whole intermediates/javac and tmp/kotlin-classes directories, covering every variant. Assembling a variant other than project.ext.selectedBuildType (e.g. assembleRelease without -Prelease) with that variant's classes already present failed Gradle's validation: "Task ':app:buildMetadata' uses this output of task ':app:compileReleaseJavaWithJavac' without declaring an explicit or implicit dependency". Declare, lazily and unconditionally, exactly the directories the task's doFirst reads: intermediates/javac/ and tmp/kotlin-classes/ of every subproject. The app's own compile tasks were already dependencies; order after the other subprojects' compile tasks of the selected build type with mustRunAfter so library-only builds are not pulled into an app build. --- test-app/app/build.gradle | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index 9fbc263bf..2aa5636f8 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -973,14 +973,23 @@ task buildMetadata(type: BuildToolTask) { // use explicit inputs as the above makes the whole build-tools directory an input! inputs.files("$BUILD_TOOLS_PATH/whitelist.mdg", "$BUILD_TOOLS_PATH/blacklist.mdg") - def classesDir = layout.buildDirectory.dir("intermediates/javac").get().asFile - if (classesDir.exists()) { - inputs.dir(classesDir) - } - - def kotlinClassesDir = layout.buildDirectory.dir("tmp/kotlin-classes").get().asFile - if (kotlinClassesDir.exists()) { - inputs.dir(kotlinClassesDir) + // Must mirror the directories doFirst scans. Declared lazily because they don't exist + // yet at configuration time on a clean build, and limited to the selected build type + // so the other variant's compile outputs never overlap this task's inputs. + def compiledClassesBuildType = project.ext.selectedBuildType + inputs.files(rootProject.subprojects.collectMany { sub -> + [sub.layout.buildDirectory.dir("intermediates/javac/$compiledClassesBuildType"), + sub.layout.buildDirectory.dir("tmp/kotlin-classes/$compiledClassesBuildType")] + }).withPropertyName("compiledClasses") + + // This project's compile tasks are dependencies (see applicationVariants above). For + // other subprojects only order after them: ones the app depends on are already reached + // transitively, and a hard dependency would drag unrelated modules into the build. + def compiledClassesTaskNames = ["JavaWithJavac", "Kotlin"].collect { "compile${compiledClassesBuildType.capitalize()}$it" } + rootProject.subprojects.each { sub -> + if (sub != project) { + mustRunAfter { compiledClassesTaskNames.collect { sub.tasks.findByName(it) }.findAll { it != null } } + } } outputs.files("$METADATA_OUT_PATH/treeNodeStream.dat", "$METADATA_OUT_PATH/treeStringsStream.dat", "$METADATA_OUT_PATH/treeValueStream.dat") From 34c0351f96d12206db1791b86927492bbbdb4b3d Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sun, 8 Nov 2026 17:51:57 -0300 Subject: [PATCH 2/2] fix(build): fingerprint the jars buildMetadata reads instead of a missing file buildMetadata declared inputs.files("mdg-java-dependencies.txt"), which resolves against the app project directory where no such file exists; the list lives in build-tools/. Adding, removing or replacing a dependency jar (an App_Resources/Android/libs jar, a plugin jar, or an updated AAR) therefore never re-ran the generator unless the app's own classes also changed, and the APK kept stale metadata for the library. Pointing the input at the real file is not enough: collectAllJars rewrites it every build and buildMetadata's doFirst appends the class directories to it, so the task would be fingerprinting a file it mutates. Instead, declare the jar files the list names (".jar" lines only; the class directories are already the compiledClasses input), resolved through a provider so the list is read after collectAllJars has written it. --- test-app/app/build.gradle | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index 2aa5636f8..d90f7ffe0 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -966,7 +966,13 @@ task buildMetadata(type: BuildToolTask) { description = "builds metadata with provided jar dependencies" - inputs.files("$MDG_JAVA_DEPENDENCIES") + // collectAllJars rewrites this list on every build and doFirst then appends the class + // directories to it, so fingerprint the jars it names rather than the file itself. Must + // stay a provider: the list is only current once collectAllJars has run. + def mdgJavaDependenciesFile = file("$BUILD_TOOLS_PATH/$MDG_JAVA_DEPENDENCIES") + inputs.files(provider { + mdgJavaDependenciesFile.exists() ? mdgJavaDependenciesFile.readLines().findAll { it.endsWith(".jar") } : [] + }).withPropertyName("dependencyJars") // make MDG aware of whitelist.mdg and blacklist.mdg files // inputs.files(project.fileTree(dir: "$rootDir", include: "**/*.mdg"))