无法为 react-native 应用程序集成 react-native-maps

Can't integrate react-native-maps for react-native app

我是 react-native 的新手,当我尝试将 react-native-maps 与我的 react native 应用程序集成时,出现以下错误。

FAILURE: Build failed with an exception.

* Where:
Settings file 'D:\React-Projects\Native\ReactNativeMaps\android\settings.gradle' line: 3

* What went wrong:
Could not compile settings file 'D:\React-Projects\Native\ReactNativeMaps\android\settings.gradle'.
> startup failed:
  settings file 'D:\React-Projects\Native\ReactNativeMaps\android\settings.gradle': 3: unexpected char: '\' @ line 3, column 111.
       node_modules\react-native-maps\lib\andro
                               ^

1 个错误

这是我的 build.gradle 依赖项数组。

dependencies {
    implementation project(':react-native-maps'){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:12.0.0'
    implementation 'com.google.android.gms:play-services-maps:12.0.0'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

这是我的 settings.gradle 文件内容。

rootProject.name = 'ReactNativeMaps'
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '..\node_modules\react-native-maps\lib\android')

include ':app'

如果有人需要查看完整错误,

$ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

FAILURE: Build failed with an exception.

* Where:
Settings file 'D:\React-Projects\Native\ReactNativeMaps\android\settings.gradle' line: 3

* What went wrong:
Could not compile settings file 'D:\React-Projects\Native\ReactNativeMaps\android\settings.gradle'.
> startup failed:
  settings file 'D:\React-Projects\Native\ReactNativeMaps\android\settings.gradle': 3: unexpected char: '\' @ line 3, column 111.
     node_modules\react-native-maps\lib\andro
                                   ^

  1 error


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Command failed: gradlew.bat installDebug

Error: Command failed: gradlew.bat installDebug
    at checkExecSyncError (child_process.js:616:11)
    at Object.execFileSync (child_process.js:634:13)
    at runOnAllDevices (D:\React-Projects\Native\ReactNativeMaps\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
    at buildAndRun (D:\React-Projects\Native\ReactNativeMaps\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
    at isPackagerRunning.then.result (D:\React-Projects\Native\ReactNativeMaps\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)

我也通过以下命令安装了 react-native-map,link 它也安装了。

npm install --save react-native-maps
react-native link react-native-maps

这是 package.json 文件。

{
  "name": "ReactNativeMaps",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.3",
    "react-native": "0.58.4",
    "react-native-maps": "^0.23.0"
  },
  "devDependencies": {
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.1.0",
    "jest": "24.1.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

出了什么问题?我错过了什么吗?

在您的 package.json 中更改 react-native-maps 如下:

"react-native-maps": "https://github.com/react-community/react-native-maps.git"

settings.gradle 中确保您的第 3 行是:

project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')

检查这是否有效。

我发现了问题。构建的原因是API_KEY。我用新的 api 键替换了 api-键,它现在可以工作了。以及更改行

project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')

还有