【问题标题】:react-native-map crashing the applicationreact-native-map 使应用程序崩溃
【发布时间】:2019-08-11 04:18:04
【问题描述】:

我尝试使用 react native app 并在 gradle 文件中有以下 sn-p

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
}

我用谷歌搜索,发现下面的行解决了问题

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",

如何解决此问题

【问题讨论】:

  • implementation 替换 compile。所以你可以切换它。所以在你看到compile 的地方,请改用implementation。
  • 我没听懂
  • 好的好的,让我检查一下

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


【解决方案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 中使用您的标准 react-native 设置,不要尝试在此处排除组 - 这对我不起作用。

这使得 Android

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

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

【讨论】:

    【解决方案2】:

    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
    }
    

    【讨论】:

    • 是的,我明白了,但现在我收到错误 Android 依赖项 'com.google.android.gms:play-services-location' has different version for the compile (11.8.0) and runtime (11.4) .2) 类路径。您应该通过 DependencyResolution 手动设置相同的版本
    • 这可能是因为您使用的是+ 应该使用特定版本的播放服务位置。使用 + 从来都不是一个好主意,因为它只是安装最新的并且可能导致构建问题
    【解决方案3】:

    +1 来自@hsearle 的回答 在我们的例子中,我们使用 react-native-maps,我假设它们以某种方式链接(猜猜谁不是真正的 react-native 专家);)

    无论如何,我们更新到 SDK 28 并且地图开始使应用程序崩溃。

    AndroidManifest.xml 的应用程序元素中的以下代码为胜利!

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

    【讨论】:

    • 就我而言,我只用这段代码解决了这个问题。
    【解决方案4】:

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

    【讨论】:

    • 不,我在当前文件中,我在这个文件中有所有依赖项,android/build.gradle 说“依赖项 { classpath 'com.android.tools.build:gradle:3.2.1' / / 注意:不要将您的应用程序依赖项放在此处;它们属于 // 在单独的模块 build.gradle 文件中 }"
    • 打开这个 Project/android/app/build.gradle 。你已经打开了 Project/android/build.gradle
    【解决方案5】:

    这是底层地图库的问题。另请参阅 Google 提供的此文档:-https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library

    解决办法是:- 把这行代码放在Manifest文件的&lt;application&gt;标签下:

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

    【讨论】:

      【解决方案6】:

      世博会:

      "android": {
         "package": "com.codingmechanic.mapcuny",
         "config": {
            "googleMaps": { "apiKey": "<Your API Key>" }   
         }
      }
      

      Create a React Native App with Google Map using Expo.io

      【讨论】:

        猜你喜欢
        • 2017-01-30
        • 1970-01-01
        • 1970-01-01
        • 2018-02-17
        • 1970-01-01
        • 1970-01-01
        • 2022-10-04
        • 2022-01-02
        • 2017-01-16
        相关资源
        最近更新 更多