错误:react-native-permissions:NativeModule.RNPermissions 为 null

nou*_*one 6 android react-native

我在启动 React Native Android 应用程序时遇到此错误。\n Error: react-native-permissions: NativeModule.RNPermissions is null. To fix this issue try these steps: \xe2\x80\xa2 If you are using CocoaPods on iOS, run pod install in theios directory and then clean, rebuild and re-run the app. You may also need to re-open Xcode to get the new pods. \xe2\x80\xa2 If you are getting this error while unit testing you need to mock the native module. You can use this to get started: https://github.com/react-native-community/react-native-permissions/blob/master/mock.js If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-permissions

\n

我已按照错误正文中提到的步骤进行操作,但没有成功。\n我遵循的步骤:

\n
    \n
  1. 吊舱安装
  2. \n
  3. 清理并重建应用程序
  4. \n
  5. npx 反应本机清洁项目
  6. \n
\n

我的 Pod 文件:

\n
require_relative '../node_modules/react-native/scripts/react_native_pods'\nrequire_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'\npermissions_path = '../node_modules/react-native-permissions/ios'\npod 'Permission-Camera', :path => "#{permissions_path}/Camera"\n# pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone.podspec"\npod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"\nplatform :ios, '11.0'\n\ntarget 'BayQi' do\n  pod 'react-native-contacts', :path => '../node_modules/react-native-contacts'\n  rn_maps_path = '../node_modules/react-native-maps'\n  pod 'react-native-google-maps', :path => rn_maps_path\n  pod 'GoogleMaps'\n  pod 'Google-Maps-iOS-Utils'\n  config = use_native_modules!\n\n  use_react_native!(:path => config["reactNativePath"])\n\n\n\n  target 'BayQiTests' do\n    inherit! :complete\n    # Pods for testing\n  end\n\n  # Enables Flipper.\n  #\n  # Note that if you have use_frameworks! enabled, Flipper will not work and\n  # you should disable these next few lines.\n  # use_flipper!\n  # post_install do |installer|\n  #   flipper_post_install(installer)\n  # end\nend\n\ntarget 'BayQi-tvOS' do\n  # Pods for BayQi-tvOS\n\n  target 'BayQi-tvOSTests' do\n    inherit! :search_paths\n    # Pods for testing\n  end\nend\n
Run Code Online (Sandbox Code Playgroud)\n

Zak*_*try 19

这是因为react-native-qrcode-scanner使用的是旧版本react-native-permissions。对于这种情况,典型的解决方案之一是覆盖依赖项。覆盖react-native-permissions的依赖关系react-native-qrcode-scanner。对于npm,我们需要使用覆盖,对于yarn,我们需要使用分辨率。

因此,对于此代码,只需删除 node_modules 文件夹、yarn.lock 文件,然后将此代码添加到 package.json 即可

  "resolutions": {
    "react-native-permissions": "^3.8.0"
  },
  "overrides": {
    "react-native-qrcode-scanner": {
      "react-native-permissions": "^3.8.0"
    }
  },
Run Code Online (Sandbox Code Playgroud)

比运行yarn或npm安装。我的 package.json 如下所示:

  "dependencies": {
...
    "react": "18.2.0",
    "react-native": "0.71.4",
...
    "react-native-permissions": "^3.8.0",
    "react-native-qrcode-scanner": "^1.5.5",
...
  },
...
  "resolutions": {
    "react-native-permissions": "^3.8.0"
  },
  "overrides": {
    "react-native-qrcode-scanner": {
      "react-native-permissions": "^3.8.0"
    }
  },
Run Code Online (Sandbox Code Playgroud)

使用yarn,这个package.json 效果很好。


小智 10

经过两天的调试react-native-permissions,我发现我的问题出在react-native-qrcode-scanner.

它具有"react-native-permissions": "^2.0.2"依赖项,但当前版本是"react-native-permissions": "^3.8.0".

此版本react-native-permissions (3.8.0)有重大更改。

快速解决

  1. 安装react-native-permissions并按照安装说明进行操作。
  2. 删除,node_modules/react-native-qrcode-scanner/node_modules/react-native-permissions因为它安装了已弃用的2.0.2. (每次清除 node_modules 时都需要执行此操作)

在您的情况下,您需要找到react-native-permissions作为依赖项安装的库,然后删除node_modules/*specific-library*/node_modules/react-native-permissions

https://github.com/moaazsidat/react-native-qrcode-scanner/issues/403


Sau*_*rav 4

我通过以下步骤修复了它

考虑到库中的未决问题,将 package.json 文件中的 React-native-permissions 版本从 3.8.0 更改为 2.0.2,参考 - https://github.com/moaazsidat/react-native-qrcode-scanner/issues /411

将以下内容添加到 Podfile 中

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
Run Code Online (Sandbox Code Playgroud)

不要忘记在最后添加 .podspec,记住这是旧版本的react-native-permissions。

将这些添加到 Info.plist 文件

<key>NSCameraUsageDescription</key>
<string>Our app need your permission to use your camera phone</string>
<!-- Include this only if you are planning to use the camera roll -->
<key>NSPhotoLibraryUsageDescription</key>
<string>Your message to user when the photo library is accessed for the first time</string>
Run Code Online (Sandbox Code Playgroud)

确保您已添加react-native-camera 软件包以使相机正常工作。

现在从 ios 文件夹运行 npm install 和 pod install。