Skip to content

[Android] Release build fails with R8: duplicate TurboModule spec classes (e.g. NativeCalendarEventModuleSpec) when New Architecture + app codegenConfig #18

@isinuyk

Description

@isinuyk

Environment
@appzung/react-native-code-push: 11.0.3 (adjust if different)
react-native: 0.84.x (New Architecture enabled)
Android Gradle Plugin / Gradle: (your versions)
Repro: assembleDevRelease (or any release variant with minifyEnabled true / R8)

Symptom
Release build fails at :app:minify*ReleaseWithR8 with an error similar to:

R8: Type com..NativeCalendarEventModuleSpec is defined multiple times:
.../transforms/.../classes.jar:com//NativeCalendarEventModuleSpec.class
.../app/build/intermediates/.../com//NativeCalendarEventModuleSpec.class
Debug builds without R8/ProGuard often succeed.

Expected behavior
The host app should be able to use CodePush, New Architecture, app-level codegenConfig / Turbo Modules, and R8 in release without duplicate classes.

Actual behavior
R8 reports duplicate definitions of app-generated TurboModule spec classes (same package as codegenConfig.android.javaPackageName), because those classes appear both in the app compile output and in a dependency produced from this library.

Root cause (analysis)
react-native.config.js sets android.sourceDir to ./android/app.

android/app/build.gradle applies com.facebook.react when New Architecture is enabled.

React Native’s Gradle plugin registers codegen for library projects (configureCodegen(..., isLibrary = true) in ReactPlugin.kt).

For this module, findPackageJsonFile does not find android/package.json, so it resolves the host app’s package.json (with codegenConfig).

The codegen task’s onlyIf includes isLibrary, so the app’s TurboModule Java specs are generated under this library’s build/generated/source/codegen/java/... and compiled into the CodePush AAR, duplicating the same classes generated in :app.

CodePush’s own src does not appear to need these generated specs.

Suggested direction (for maintainers)
Preferred: Stop applying com.facebook.react on the CodePush library if it is not required for JNI/codegen, or restrict codegen so the library does not run host app TurboModule codegen (e.g. align with how other RN libraries avoid duplicating app specs).

Optional doc: Warn that apply plugin: "com.facebook.react" on a library under the app’s monorepo can duplicate app codegen when sourceDir is android/app and there is no intervening package.json without codegenConfig.

Minimal repro
RN 0.7x+ with New Arch on, newArchEnabled=true.
App package.json with codegenConfig (Turbo Modules) and android.javaPackageName set (e.g. com.example.app).
Install @appzung/react-native-code-push, release build with minifyEnabled true.
Observe R8 duplicate class on Native*ModuleSpec for that package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions