首页 > 解决方案 > React-Native - react-native-update-gradle - 错误

问题描述

我的 Android 版 React-Native 项目出现错误。

我的第一个错误如下:

我添加了“react-native-location”库。在我运行命令“react-native link”后,抛出了错误“compileOnly”。所以我的第一次尝试是更新 NPM 和 Node.JS。但这不是我的问题的正确解决方案。

在那之后,我用谷歌搜索了错误,我想用“react-native-update-gradle”更新grandle。我现在的主要问题是,当我运行“react-native link”命令时,出现以下错误:

    C:\Computer\Apps\Projects\XXX>react-native link
Scanning folders for symlinks in C:\Computer\Apps\Projects\XXX\node_modules (70ms)
rnpm-install info Platform 'ios' module react-native-orientation is already linked
rnpm-install info Platform 'android' module react-native-orientation is already linked
internal/validators.js:125
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:125:11)
    at Object.join (path.js:427:7)
    at getSDKPath (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\index.js:13:12)
    at getPTPath (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\index.js:17:20)
    at Object.activateADB (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\index.js:5:42)
    at Object.<anonymous> (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\cli.js:101:6)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
C:\Computer\Apps\Projects\XXX\node_modules\react-native\local-cli\core\makeCommand.js:27
        throw new Error(`Error occurred during executing "${command}" command`);
        ^

Error: Error occurred during executing "node ./node_modules/react-native-update-gradle/cli.js" command
    at ChildProcess.prelink (C:/Computer/Apps/Projects/XXX/node_modules/react-native/local-cli/core/makeCommand.js:27:15)
    at ChildProcess.emit (events.js:197:13)
    at maybeClose (internal/child_process.js:978:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)

我试图修复错误,但错误仍然存​​在。

我有以下环境

安卓/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com'
        }
    }
}

ext {
    compileSdkVersion   = 28
    targetSdkVersion    = 28
    buildToolsVersion   = "28.0.3"
    supportLibVersion   = "28.1.1"
    playServicesVersion = "15.0.1"
}

包.json

 {
  "name": "XXX",
  "version": "1.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "run-android": "react-native run-android"
  },
  "dependencies": {
    "react": "16.3.1",
    "react-native": "0.55.4",
    "react-native-image-slider": "^2.0.3",
    "react-native-image-zoom-viewer": "^2.2.25",
    "react-native-orientation": "^3.1.3",
    "react-native-pinch-zoom-view": "^0.1.6",
    "react-native-responsive-image": "^2.3.1",
    "react-native-router-flux": "^4.0.0-beta.28",
    "react-native-scrolltotop": "0.0.6",
    "react-native-slideshow": "^1.0.1",
    "react-native-swipe-gestures": "^1.0.2",
    "react-native-update-gradle": "^1.1.0",
    "react-native-vector-icons": "^4.6.0",
    "react-native-zoom-view": "^1.0.2"
  },
  "devDependencies": {
    "babel-jest": "22.4.3",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.3",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

如果您需要更多信息来帮助我,请告诉我。

谢谢你的帮助。

此致

标签: androidreact-nativegradle

解决方案


塞巴斯蒂安!运行命令后react-native link,您必须运行命令react-native run-androidreact-native run-ios. 这样您安装的库就会根据您的反应原生设置进行调整。在我安装库或包之后,这对我有用。希望这可以帮助。


推荐阅读