0

感谢您的帮助,收到错误消息“错误:传感器的本机模块不可用。react-native 链接是否成功运行?” 运行 npx react-native start 时

npx react-native run-android 给出此错误:> 安装 react-native-sensors 后任务:app:processDebugManifest FAILED。

安装程序:

npx react-native init proj8

cd proj8

npm install react-native-sensors --save

npx react-native 链接 react-native-sensors

最后一个命令报告成功,但是当我通过手动 Android 程序时,某些部分未完成,如下所示:

import com.sensors.RNSensorsPackage;

在 android/app/src/main/java/[...]/MainApplication.java

new RNSensorsPackage() 不在那里,我添加如下:

@Override
       protected List<ReactPackage> getPackages() {
       @SuppressWarnings("UnnecessaryLocalVariable")
       List<ReactPackage> packages = new PackageList(this).getPackages();
       // Packages that cannot be autolinked yet can be added manually here, for example:
       // packages.add(new MyReactNativePackage());
       packages.add(new RNSensorsPackage());
       return packages;
}
include ':react-native-sensors'
project(':react-native-sensors').projectDir = new File(rootProject.projectDir,  '../node_modules/react-native-sensors/android')

都在 android/settings.gradle

dependencies {
    implementation project(':react-native-sensors')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

我必须添加实施项目(':react-native-sensors')

我认为我的代码并不重要,但 App.js:

import React, {useState, useEffect, useRef} from 'react';
import { StyleSheet,ScrollView,SafeAreaView,Platform, View,Text } from 'react-native';

export default function App() {
    var Rndr = 
        <Text>asdf</Text>
    return Rndr
}

包.json:

{
  "name": "proj8",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.13.1",
    "react-native": "0.63.3",
    "react-native-sensors": "^7.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "^25.1.0",
    "eslint": "^6.5.1",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "react-test-renderer": "16.13.1"
  },
  "jest": {
    "preset": "react-native"
  }
}
4

1 回答 1

1

我遇到了同样的问题。出现这种情况是因为react-native-sensors的 minsdk 版本是 17,而 react-native 的默认 minsdk 版本是 16,这很容易解决。

  1. 只需转到android/build.gradle
  2. 将 minSdkVersion更改为 17 以上的任何值

 ext {
    buildToolsVersion = "29.0.2"
    minSdkVersion = 16
    compileSdkVersion = 29
    targetSdkVersion = 29
}

 ext {
    buildToolsVersion = "29.0.2"
    minSdkVersion = 19
    compileSdkVersion = 29
    targetSdkVersion = 29
}
于 2020-11-20T20:02:22.653 回答