我按照这里的指示https://github.com/react-native-community/react-native-maps/blob/master/docs/installation.md在我的react-native项目上使用MapView。我写在我的谷歌MapAPI键的好地方,但代码仍然找不到它。有时这个错误不出现,我的应用程序只是崩溃。
我的react-native版本是0.60.4,所以我只对版本0.59和更高版本进行了修改,但为了验证,我还尝试了其他修改,但没有解决这个问题。
这是安卓系统/app/src/main/安卓系统清单. 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>
这是安卓/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+"
}
这是我的App.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',
}
})
我只是期望解决这个问题:/
2条答案
按热度按时间cxfofazt1#
如果您的React-Native版本低于(0.6),您必须将其添加到设置.gradle文件中
如果这错误持续请跟随这docs小心在github react-native-maps installation
cgfeq70w2#
在我的情况下,这是因为应用程序正在运行。停止您正在运行的应用程序,并重新运行它。