Repository navigation
Android autolinking: a library limited to debug by buildTypes is still in the release variant's PackageList.java, so the release build does not compile #59692
Description
Description
A library whose react-native.config.js sets dependency.platforms.android.buildTypes: ['debug'] is added to the app only as debugImplementation, as intended, but the Gradle plugin's generated PackageList.java still names its package class. That file is compiled by every variant, so the release variant fails with package … does not exist. buildTypes therefore can't keep a library with a ReactPackage out of a release build, which is what I'd expect it to be for.
In the Gradle plugin at main (6cfbbdfefb):
ReactExtension.ktadds the library under${buildType}Implementationfor each listed build type.GeneratePackageListTask.filterAndroidPackageskeeps every dependency with an Android platform, without looking atbuildTypes.ReactPlugin.ktadds the one generatedPackageList.javato every variant's sources.
The same thing was reported against the community CLI's autolinking in react-native-community/cli#2282, which was closed as stale.
Steps to reproduce
- Clone https://github.com/YevheniiKotyrlo/rn-build-types-package-list.
ReproducerApp/modules/debug-only-libraryis a local library with aReactPackage(com.debugonlylibrary.DebugOnlyPackage) and areact-native.config.jsthat setsplatforms.android.buildTypes: ['debug']; the app depends on it withfile:. - In
ReproducerApp, runyarn install. - In
ReproducerApp/android, run./gradlew :app:compileDebugJavaWithJavac :app:compileReleaseJavaWithJavac --continue.
Expected: both variants compile, the release one without the library.
Actual: the debug variant compiles, and the release variant fails:
> Task :app:compileReleaseJavaWithJavac FAILED
D:\work\contributions\rn-build-types-package-list\ReproducerApp\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:61: error: package com.debugonlylibrary does not exist
new com.debugonlylibrary.DebugOnlyPackage()
^
1 error
React Native Version
0.89.0-nightly-20261030-4afc5d5b9
Affected Platforms
Build - Windows
Output of npx @react-native-community/cli info
System:
OS: Windows 11 10.0.26300
CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor "
Memory: 132.59 GB / 255.67 GB
Binaries:
Node:
version: 26.12.1
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 1.22.22
path: C:\Users\yevhe.YEVHENII\AppData\Roaming\npm\yarn.CMD
npm:
version: 12.2.1
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
API Levels:
- "33"
- "35"
- "35"
- "35"
- "36"
- "37"
- "37"
Build Tools:
- 35.0.0
- 36.0.0
- 36.1.0
- 37.0.0
System Images:
- android-26 | Google APIs Intel x86_64 Atom
- android-28 | Google APIs Intel x86_64 Atom
- android-29 | Google APIs Intel x86_64 Atom
- android-30 | Google APIs Intel x86_64 Atom
- android-31 | Google APIs Intel x86_64 Atom
- android-32 | Google APIs Intel x86_64 Atom
- android-33 | Google APIs Intel x86_64 Atom
- android-34 | Google APIs Intel x86_64 Atom
- android-35 | Google APIs Intel x86_64 Atom
- android-36.1 | Google Play Intel x86_64 Atom
- android-36.1 | Pre-Release 16 KB Page Size Google Play Intel x86_64 Atom
- android-37.0 | Google APIs Intel x86_64 Atom
Android NDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: AI-262.9437.185.2621.16467767
Visual Studio: Not Found
Languages:
Java:
version: 17.0.20.1
path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
Ruby: Not Found
npmPackages:
"@react-native-community/cli":
installed: 21.0.0-alpha.1
wanted: 21.0.0-alpha.1
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.89.0-nightly-20261030-4afc5d5b9
wanted: 0.89.0-nightly-20261030-4afc5d5b9
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Stacktrace or Logs
* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler output below.
D:\work\contributions\rn-build-types-package-list\ReproducerApp\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:61: error: package com.debugonlylibrary does not exist
new com.debugonlylibrary.DebugOnlyPackage()
^
1 error
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/rn-build-types-package-list
Screenshots and Videos
No response
Activity