我是react-native的新手,当我尝试将react-native-map与我的react本地应用程序集成时,会出现以下错误。
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并也链接了它。
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"
}
}
出了什么问题?我错过了什么吗?
答案 0 :(得分:0)
在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')
检查是否可行。
答案 1 :(得分:0)
我发现了问题。构建的原因是API_KEY。我将api-key替换为新的api密钥,并且它现在可以正常工作。以及更改行
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
也