react-native-map使应用程序崩溃

时间:2019-03-20 12:57:59

标签: google-maps react-native react-native-android react-native-maps

我尝试使用react native应用并在gradle文件中包含以下代码段

dependencies {
    implementation project(':react-native-maps')
    implementation project(':react-native-geolocation-service')
    implementation project(':react-native-background-timer')
    implementation project(':react-native-mauron85-background-geolocation')
    implementation project(':react-native-contacts')
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

我已经用Google搜索并找到解决问题的以下行

compile(project(':react-native-maps')) {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    compile 'com.google.android.gms:play-services-base:11.+'
    compile 'com.google.android.gms:play-services-maps:11.+'
    compile 'com.google.android.gms:play-services-location:+'

但是我没有gradle文件中的compile(project ....

我正在使用

 "react": "16.6.3",
 "react-native": "0.58.6",
 "react-native-geolocation-service": "^2.0.0",
 "react-native-gesture-handler": "^1.1.0",
 "react-native-maps": "^0.23.0",

如何解决此问题

5 个答案:

答案 0 :(得分:1)

我在这上面花了很长时间,最后偶然发现了两件事。这进入您的项目的build.gradle(而不是app/build.gradle的项目):

allprojects {
    repositories {
        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion '12.0.1'
                }
                if (requested.group == 'com.google.firebase') {
                    details.useVersion '12.0.1'
                }
            }
        }
        // ... whatever else you have here already
    }
}

只需使用app/build.gradle中的标准反应本机设置,不要尝试在此处排除组-这对我不起作用。

这使Android <9.0可以正常工作-很棒。但是9.0+崩溃了,不是很酷。我随机发现了这些信息:

If you are using com.google.android.gms:play-services-maps:16.0.0 
or below and your app is targeting API level 28 (Android 9.0) or 
above, you must include the following declaration within the 
<application> element of AndroidManifest.xml.

<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" 
/>

https://developers.google.com/maps/documentation/android-sdk/config#specify_the_google_play_services_version_number

我真的希望这个库能尽快升级。我希望这对某人有帮助。

答案 1 :(得分:0)

您打开了错误的文件。进入Project / android / app / build.gradle 打开构建文件并粘贴依赖项

答案 2 :(得分:0)

已弃用

compile,而推荐使用implementation。您可以轻松地将单词compile的所有实例替换为单词implemenation。因此,您的依赖项将变成这样:

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:11.+'
    implementation 'com.google.android.gms:play-services-maps:11.+'
    implementation 'com.google.android.gms:play-services-location:+'


    // implementation project(':react-native-maps') // <- you can remove this as you are using it above
    implementation project(':react-native-geolocation-service')
    implementation project(':react-native-background-timer')
    implementation project(':react-native-mauron85-background-geolocation')
    implementation project(':react-native-contacts')
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

答案 3 :(得分:0)

+1以获取@hsearle的答案 在我们的例子中,我们使用了react-native-maps,我假设它们以某种方式链接(猜测谁不是bonifide react-native专家);)

无论如何,我们更新到SDK 28,地图开始崩溃。

下面是AndroidManifest.xml的application元素中的代码!

    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" 
    />

答案 4 :(得分:0)

这是基础地图库的问题。另请参阅以下来自Google的文档:-https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library

解决方案是:-将以下代码行放在清单文件中的<application>标签下:

`<uses-library android:name="org.apache.http.legacy" android:required="false"/>`