Skip to content

Android: WorkletsPackage class name collision with react-native-worklets on RN 0.83+ #266

Description

@thisisdice

Description

On React Native 0.83+, react-native-worklets-core fails to compile on Android due to a class name collision with react-native-worklets (Reanimated 4 dependency).

Both packages export a class named WorkletsPackage, causing autolinking to generate ambiguous imports in PackageList.java.

Environment

  • React Native: 0.83.1
  • react-native-worklets-core: 2.0.0-beta.4
  • react-native-worklets: 0.7.2 (peer dependency of Reanimated 4.2.1)
  • react-native-vision-camera: 4.7.3
  • react-native-reanimated: 4.2.1

Error

error: a type with the same simple name is already defined by the single-type-import of WorkletsPackage
import com.margelo.worklets.WorkletsPackage;
                   ^
/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:86: error: reference to WorkletsPackage is ambiguous

Root Cause

  • react-native-worklets: com.swmansion.worklets.WorkletsPackage
  • react-native-worklets-core: com.margelo.worklets.WorkletsPackage

RN 0.83's stricter autolinking generates both imports, causing Java compilation failure.

Workaround

Exclude react-native-worklets-core from autolinking and manually register:

react-native.config.js:

module.exports = {
  dependencies: {
    'react-native-worklets-core': {
      platforms: { android: null }
    }
  }
};

MainApplication.kt:

PackageList(this).packages.apply {
  add(com.margelo.worklets.WorkletsPackage())
}

Proposed Fix

Rename the Java class to avoid collision:

  • WorkletsPackageWorkletsCorePackage

This would align with the package name and prevent conflicts with Software Mansion's react-native-worklets.

Additional Context

  • This only affects RN 0.83+ (confirmed working on RN 0.81.5)
  • Both packages are required (VisionCamera needs worklets-core, Reanimated needs worklets)
  • No JSI/C++ collision — purely Android autolinking issue
  • The two packages coexist fine at the native layer (different C++ namespaces)

Activity

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