Skip to content

fix(build): declare buildMetadata's real inputs - #2095

Merged
edusperoni merged 2 commits into
mainfrom
fix/build-metadata-inputs
Nov 8, 2026
Merged

edusperoni merged 2 commits into
mainfrom
fix/build-metadata-inputs

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes how the buildMetadata task in test-app/app/build.gradle declares its inputs. That file is copied into the app template, so this affects every app's build.

Stale metadata after a clean build. The task 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 (a clean build with existing metadata) the task had no class inputs, was considered UP-TO-DATE, and was skipped. The APK then shipped stale metadata, and newly added Java/Kotlin classes were undefined from JS.

Validation failure when assembling the non-selected variant. The task declared the whole intermediates/javac and tmp/kotlin-classes directories, covering every variant. Assembling a variant other than selectedBuildType while that variant's classes already existed (for example assembleRelease without -Prelease) failed with:

Task ':app:buildMetadata' uses this output of task ':app:compileReleaseJavaWithJavac' without declaring an explicit or implicit dependency

The fix: declare, lazily and unconditionally, exactly the directories the task's doFirst reads: intermediates/javac/<selectedBuildType> and tmp/kotlin-classes/<selectedBuildType> of every subproject.

  • The app's own compile tasks were already dependencies.
  • Other subprojects' compile tasks for the selected build type are only ordered before this task (mustRunAfter). Unrelated library modules are never pulled into an app build, and no finalizedBy hooks are added.

Dependency jars weren't inputs either. inputs.files("$MDG_JAVA_DEPENDENCIES") resolved to app/mdg-java-dependencies.txt, a path that doesn't exist; the real list is under build-tools/. So changing a dependency jar alone (a plugin update, or a jar in App_Resources/Android/libs) didn't re-run the task. Pointing at the right file isn't enough: collectAllJars rewrites that list on every build, and buildMetadata's own doFirst appends the class directories to it, so the task would be watching a file it mutates. The second commit instead fingerprints the jar files the list names, filtered to .jar entries. The list is read through a provider, so it is current: collectAllJars always runs first.

Verification

All runs used -Pabis=arm64-v8a -PuseKotlin=true. "Count" is grep -a -c <class> on treeStringsStream.dat.

  • Debug:

    Step buildMetadata Result
    Add a new Java class, rm -rf app/build, build runs class present (count 1)
    No-change rebuild UP-TO-DATE —
    Comment-only edit UP-TO-DATE —
    Add a public method runs method present
    Add a Kotlin class, clean runs class present
    Remove the classes runs count 0
  • Release (-Prelease with signing props): clean build passes, a second no-clean build is UP-TO-DATE and passes, and a new class after a clean build is present.

  • Non-selected variant: :app:mergeReleaseAssets without -Prelease, with release classes present, now passes the validation.

  • Dry runs: debug and release task graphs have no cycles and order the compile tasks before buildMetadata. :runtime:assembleRelease pulls in no :app: tasks.

  • Dependency jars: a probe jar added under App_Resources/Android/libs re-runs the task and shows up in metadata. Replacing it with a new version re-runs it again, and removing it re-runs it and drops the class. Two or three consecutive no-change builds stay UP-TO-DATE, so the appended class folders never cause reruns. Release: the first build runs the task, and the next two are UP-TO-DATE.

Notes

  • Configure-on-demand: the ordering closure looks up other subprojects' tasks when the graph is built. A subproject that was never configured simply gets no ordering, and nothing fails.

Does your pull request have unit tests?

No. This is build wiring, verified by the build matrix above.

… 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/<selectedBuildType> and
tmp/kotlin-classes/<selectedBuildType> 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.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…sing 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.
@edusperoni edusperoni changed the title fix(build): declare buildMetadata inputs per build type fix(build): declare buildMetadata's real inputs Nov 8, 2026
@edusperoni
edusperoni marked this pull request as ready for review November 8, 2026 21:01
@edusperoni
edusperoni merged commit b24937a into main Nov 8, 2026
7 of 8 checks passed
@edusperoni
edusperoni deleted the fix/build-metadata-inputs branch November 8, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant