React-Native-worklets-core 错误:未找到工作集,即使我安装了它

问题描述 投票:0回答:1

因此,我尝试使用 React-Native 开发一个使用 Google ML Kit 姿势检测的 Android 应用程序。我仍处于该项目的开始阶段,但我的第一个目标是启动应用程序并查看姿势检测是否有效。因此,我需要用于帧处理器的react-native-vision-camera和react-native-worklets-core包。 只是为了让您知道,在 App.tsx 中我使用这样的帧处理器:

//[...]
 const frameProcessor = useFrameProcessor((frame: any) => {
    'worklet';
    const poseObject = objectDetect(frame);

 //[...]

并将其包含在相机组件中作为回报:

return (
    <>
      <Camera
        frameProcessor={frameProcessor}
        style={StyleSheet.absoluteFill}
        device={device}
        isActive={true}
      />
//[...]

目前我还在使用Android Studio的模拟器。 我按照 React-Native-Vision-Camera 和 -Worklets-core 的方向进行了所有操作,构建始终成功,但应用程序在模拟器上给出了以下错误代码:

Uncaught Error

Frame Processors are not available, react-native-worklets-core is not installed! Error: TurboModuleRegistry.getEnforcing(...): 'Worklets' could not be found. Verify that a module by this name is registered in the native binary.
Bridgeless mode: false. TurboModule interop: false. Modules loaded:
{"NativeModules":["PlatformConstants","LogBox","Timing","AppState","SourceCode","BlobModule","WebSocketModule","DevSettings","DevToolsSettingsManager","Networking","Appearance","DevLoadingView","HeadlessJsTaskSupport","UIManager","DeviceInfo","ImageLoader","SoundManager","IntentAndroid","DeviceEventManager","RNGestureHandlerModule","I18nManager","ReanimatedModule"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","LinkingManager","Worklets"]}

重点是:我已经安装了worklets-core!

package.json 中我的依赖项:

  "dependencies": {
    "metro-react-native-babel-preset": "^0.77.0",
    "react": "18.2.0",
    "react-native": "0.73.6",
    "react-native-gesture-handler": "^2.14.0",
    "react-native-reanimated": "^3.6.2",
    "react-native-svg": "^15.3.0",
    "react-native-vision-camera": "^4.0.5",
    "react-native-worklets-core": "^1.3.3"
  },

以及build.gradle中的依赖项:

dependencies {
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:react-native:+")
    implementation("com.facebook.soloader:soloader:0.10.3")
    implementation 'com.google.mlkit:pose-detection:18.0.0-beta4'
    implementation 'com.google.mlkit:pose-detection-accurate:18.0.0-beta4'
    implementation 'com.google.mlkit:vision-common:17.0.0'
    implementation 'com.google.mlkit:vision-interfaces:16.0.0'
    implementation 'com.google.mlkit:camera:16.0.0-beta3'
    implementation 'androidx.annotation:annotation:1.3.0'
    implementation 'com.google.android.gms:play-services-tasks:18.0.0'
    implementation 'com.android.support:multidex:1.0.3'


    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-vision-camera')
    implementation project(':react-native-svg')
    implementation project(':react-native-worklets-core')

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

还有我的 babel 配置:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-transform-private-methods',
    '@babel/plugin-transform-flow-strip-types',
    '@babel/plugin-transform-runtime',
    '@babel/plugin-transform-arrow-functions',
    ['react-native-worklets-core/plugin'],
    ['react-native-reanimated/plugin', { globals: ['__poseDetection'] }],
  ],
};

我错过了什么吗?是否缺少我不知道的导入?

  • 我已经删除了node_modules并重新安装了几次依赖项,但仍然是同样的错误

  • 我检查了 Vision-Camera 和 Worklets-Core 的其他版本,但除了 Vision-Camera 的 V4 和 Worklets-Core 的 V1 以外的任何版本都会导致与其他依赖项的兼容性问题。对于其他任何事情:同样的错误

  • 我尝试手动将worklets-core链接到vision-camera,但对于版本1.x.x,链接被禁用,因为它根据开发人员自动执行

  • 我尝试将 worklets-core 作为对等依赖项而不是标准依赖项。这实际上导致 gradle 无法构建应用程序 我收到错误:

> Could not resolve all task dependencies for configuration ':classpath'.
      > Could not find com.facebook.react:react-native-gradle-plugin:.
        Required by:
            project :

当用作标准依赖项时,gradle 能够找到类路径

  • 我将worklets-core包含到settings.gradle中:
include ':react-native-worklets-core'
project(':react-native-worklets-core').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-worklets-core/android')

完全没有变化

  • 我在 GitHub 上检查了同样的问题,但没有一个问题是完全相同的。修复它们的策略是我刚刚在这里列出的那些
android react-native google-mlkit create-react-native-app react-native-vision-camera
1个回答
0
投票

尝试将以下行添加到您的 babel.config.js 插件数组中。这应该会在您的 React Native 应用程序中启用工作集。

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-transform-private-methods',
    '@babel/plugin-transform-flow-strip-types',
    '@babel/plugin-transform-runtime',
    '@babel/plugin-transform-arrow-functions',
    ['react-native-worklets-core/plugin'],
    ['react-native-worklets-core/inline-requires'], // Add this line
    ['react-native-reanimated/plugin', { globals: ['__poseDetection'] }],
  ],
};
© www.soinside.com 2019 - 2024. All rights reserved.