Repository navigation
Generate PackageList per variant so build-type dependencies resolve - #59739
NemesisDevX wants to merge 2 commits into
Conversation
Dependencies declaring platforms.android.buildTypes are added to the
matching ${buildType}Implementation configurations only, but
generateAutolinkingPackageList produced a single shared PackageList.java
attached to every variant. A debug-only package was therefore listed in
release builds, where the class is not on the compile classpath, and
release compilation failed.
PackageList.java is now generated once per variant into
generated/autolinking/src/<variant>/java, added as a source directory
only to that variant, and filtered so a dependency is listed when its
buildTypes list is empty or contains the variant's build type. The
generateAutolinkingPackageList task remains as a lifecycle aggregator,
and the variant-agnostic entry point file moves to
generated/autolinking/src/common/java so stale PackageList outputs left
behind by older versions can never be picked up as sources again.
Fixes react#59692
|
Hi @NemesisDevX! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Honors dependencyConfiguration overrides in addition to buildTypes: a dependency is now listed only when one of its resolved Gradle configurations (as applied by getGradleDependenciesToApply) is on the variant's actual compile classpath, read from the configuration's transitive extendsFrom closure.
Summary:
Fixes #59692
A dependency that declares
platforms.android.buildTypes(e.g.['debug']) is only added to the matching${buildType}Implementationconfiguration(s) byReactExtension. However,generateAutolinkingPackageListproduced a single sharedPackageList.java— containing every autolinked package — and that directory was attached to all variants. A debug-only package class was therefore referenced from the releasePackageList.java, where the dependency is correctly absent from the compile classpath, so:app:compileReleaseJavaWithJavacfailed withpackage <debug-only package> does not exist.PackageList.javais now generated once per variant:GeneratePackageListTaskgains an optionalbuildTypeinput; a dependency is emitted when itsbuildTypeslist is empty (shared) or contains the variant's build type — mirroring exactly the classpath scoping that${buildType}Implementationalready applies.ReactPluginregisters agenerateAutolinkingPackageList<Variant>task insideonVariants, writing togenerated/autolinking/src/<variant>/javaand attaching that directory only to its own variant. ThegenerateAutolinkingPackageListtask name is kept as a lifecycle aggregator over the per-variant tasks.ReactNativeApplicationEntryPoint.javamoves togenerated/autolinking/src/common/java. Reusing the oldsrc/main/javapath would have re-attached stalePackageList.javafiles generated by older React Native versions (persistentbuild/dirs), producing duplicate-class errors on upgrade — the new path makes that impossible by construction.Backward compatible: no buildType set → previous include-all behavior; the CLI/CLI-invoked task name is unchanged; unrelated variants are untouched.
Changelog:
[ANDROID] [FIXED] - Generate PackageList per variant so dependencies restricted to specific build types are not referenced from variants that lack them on the classpath
Test Plan:
Unit tests (
packages/gradle-plugin,./gradlew :react-native-gradle-plugin:test --tests "*GeneratePackageListTaskTest*"):filterAndroidPackagescases: matching build type included, non-matching excluded, multi-entrybuildTypesmatched on any entry, shared (buildTypes: []) included for every build type, unset build type preserves legacy include-all behavior — all pass, along with the pre-existing suite. (ReactPluginTest,ReactExtensionTest,GenerateEntryPointTaskTestalso green.)Reproduced on the issue's own reproducer (https://github.com/YevheniiKotyrlo/rn-build-types-package-list), Gradle 9.4.1 / AGP 9, Windows 11, JDK 17 toolchain, patching the included-build plugin in
node_modules/@react-native/gradle-plugin:Before —
./gradlew :app:compileDebugJavaWithJavac :app:compileReleaseJavaWithJavac --continue::app:compileDebugJavaWithJavac✅:app:compileReleaseJavaWithJavac❌PackageList.java:61: error: package com.debugonlylibrary does not exist— exact failure from the issue.After, same command with the stale
src/main/javaoutputs still on disk:BUILD SUCCESSFUL).src/debug/java/.../PackageList.javalistsSafeAreaContextPackage+DebugOnlyPackage;src/release/java/...lists onlySafeAreaContextPackage;src/debugOptimized/java/...correctly excludes it too (matchingdebugOptimizedImplementationclasspath).buildTypes: ['release']removes it from debug/debugOptimized lists and includes it in release; both compiles still green.src/main/java/.../PackageList.javafrom the previous plugin version no longer causes a duplicate-class failure because that directory is no longer a source root.Incremental: re-running the same command → all tasks
UP-TO-DATE.Configuration cache: first run stores the entry with no problems; second run reports
Reusing configuration cache/Configuration cache entry reusedwith all generation tasks up-to-date.Formatting:
ktfmt0.59.0 (the jar CI runs viayarn format-check-kotlin)--checkpasses on all touched files.Not run: full
assembleDebug/assembleReleaseAPK builds (the issue's own repro command is the javac compile tasks, which were exercised), iOS/macOS builds (Android-only change), and the repo's other test jobs — relying on CI for those.Disclosure: this change was developed with AI-agent assistance (implementation + test authoring); all listed verification commands were actually executed and their outputs are reported as observed.