Android Google Maps [React Native?]"找不到 API 密钥.检查一下.错误



我按照这里的说明 https://github.com/react-native-community/react-native-maps/blob/master/docs/installation.md 在我的反应原生项目中使用 MapView。我在好地方写了我的谷歌地图API密钥,但代码仍然找不到它。 有时此错误不会出现,我的应用程序只是崩溃。

我的 react-native 版本是 0.60.4,所以我只对版本 0.59 及更高版本进行了修改,但为了验证我也尝试了其他修改,但无法解决此问题。

这是android/app/src/main/AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="A...w"/>
</application>

这是android/build.gradle

buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
/**
+ Project-wide Gradle configuration properties
*/
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
playServicesVersion = "11.8.0" // or set latest version
androidMapsUtilsVersion = "0.5+"
}

这是我的应用程序.js

import React from 'react'
import {StyleSheet, Text, View, Button} from 'react-native'
//import Main from './screens/Main'
import Navigation from './Navigation/Navigation'
import MapView from 'react-native-maps';
export default class App extends React.Component{

_loadSports(){
}
render () {
return (
<View>
<MapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
</View>
//<Navigation/>
)
}
}

const styles = StyleSheet.create({
container : {
flex : 1,
alignItems : 'center',
justifyContent:'center',
}
})

我只是希望解决这个问题:/

如果你的 React-Native 版本小于 (0.6( 您必须将其添加到 settings.gradle 文件中

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

如果错误仍然存在,请仔细按照文档进行操作 GitHub React-native-maps installation

就我而言,这是因为应用程序正在运行。停止正在运行的应用程序并重新运行它。

最新更新