Skip to content

Android: Native Module Spec generated twice leads to Dex merging duplication #35

Closed

Description

@scyrych

Our project utilizes React Native Codegen for generating the necessary source code for our Native Modules, which is correctly placed in the host application's build path, typically under android/app/build/generated/source/codegen.

After adding @code-push-next/react-native-code-push, the Android build unexpectedly triggers Codegen a second time inside the library itself. This produces an extra copy of the same generated classes inside node_modules/@code-push-next/react-native-code-push/android/app/build/generated/source/codegen.

Because both the app and the library end up generating identical classes (for example, NativeCoreSpec under the same package namespace), the Dex merging step fails with duplicate-class errors.

We tried to disable codegen for @code-push-next/react-native-code-push with patch-package but it's not that easy.

We are using React Native 0.80.2

Activity

  1. CHOIMINSEOK commented on Dec 7, 2025

    @CHOIMINSEOK
    Collaborator

    Hey @scyrych Thanks for reaching us.

    After adding @code-push-next/react-native-code-push, the Android build unexpectedly triggers Codegen a second time inside the library itself. This produces an extra copy of the same generated classes inside node_modules/@code-push-next/react-native-code-push/android/app/build/generated/source/codegen.

    That's really interesting. So, you mean, the generated files are misplaced inside of @code-push-next/react-native-code-push package redundantly?

  2. scyrych commented on Dec 9, 2025

    @scyrych
    Author

    Hey @CHOIMINSEOK. I've created a repository when you can easily replicate my issue.

    https://github.com/scyrych/react-native-code-push-integration

    Created a React Native application in version 0.80 using @react-native-community/cli.
    I've added a turbo module based on official docs and integrated with @code-push-next/react-native-code-push for Android and iOS.

    The outcome is that the Android build fails when you attempt to create a Release build.

    To replicate it:
    Open project in Android Studio, switch Build Variant to Release.
    Next run Build -> Clean project and after that Build -> Assemble project

    After that, you should get dex merge error about duplicated Spec classes.

    One under:
    android/app/build/generated/source/codegen/jni/NativeLocalStorageSpec.h
    and duplicated under:
    node_modules/@code-push-next/react-native-code-push/android/app/build/generated/source/codegen/jni/NativeLocalStorageSpec.h

    The one under node_modules/@code-push-next/react-native-code-push/android/app/build/generated/source/codegen shouldn't exist, but for some reason it's generated.

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
               Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
               Type com.turbomoduleexample.NativeLocalStorageSpec is defined multiple times: /Users/sabastiancyrych/dev/react-native-code-push-integration/android/app/build/intermediates/project_dex_archive/release/dexBuilderRelease/out/com/turbomoduleexample/NativeLocalStorageSpec.dex, /Users/sabastiancyrych/dev/react-native-code-push-integration/node_modules/@code-push-next/react-native-code-push/android/app/build/.transforms/9698f260acd07e3e7275272cb4aa42b2/transformed/bundleLibRuntimeToDirRelease/bundleLibRuntimeToDirRelease_dex/com/turbomoduleexample/NativeLocalStorageSpec.dex
    
    Image
  3. decebalus1 commented on Dec 16, 2025

    @decebalus1

    I am running into the same issue if I add a brand new turbo module to the application. Works just fine if there is no native module added. Seems like the library delegates its codegen tasks to the main application which generates the code for both main application modules and once again for Codepush. The library doesn’t fully support new architecture seems like it still relies on the interoperability layer.

    I fixed this on my end by writing a gradle script to remove the duplicates that were generated under node_modules/@code-push-next. But I think long term the library needs to update its handling of new architecture overall

  4. julhenry commented on Dec 18, 2025

    @julhenry

    @decebalus1 we’re facing the same issue. I managed to fix it with a patch, but it was quite tricky. Could you share your script, please?

  5. CHOIMINSEOK commented on Jan 6, 2026

    @CHOIMINSEOK
    Collaborator

    Hi guys @julhenry @decebalus1 @scyrych

    I'm really sorry for late response. I've been swamped with bunch of things so far.

    I checked the issue and make a PR for addressing this. After regression test, I will release patch version.

    Special thanks for repro repo ❤️ @scyrych

    #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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