Md. Parvez Alam
Md. Parvez Alam

Reputation: 4596

react-native-map crashing the application

I tried to use react native app and having the following snippet in gradle file

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
}

I have googled and found below lines solving the issues

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:+'

But i dont have compile(project.... in my gradle file

I am using

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

How to resolve this issue

Upvotes: 1

Views: 4542

Answers (6)

K.Igor
K.Igor

Reputation: 193

For expo:

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

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

Upvotes: 0

Akshita Agarwal
Akshita Agarwal

Reputation: 255

This is an issue with the underlying maps library. Please also see this documentation from Google:-https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library

The solution is :- Put this line of code in the Manifest file under the <application> tag:

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

Upvotes: 0

Mark Lloyd
Mark Lloyd

Reputation: 161

+1 for the answer from @hsearle In our case we are using react-native-maps and I'm assuming that they somehow link (guess who is not a bonifide react-native expert) ;)

anyways we updated to SDK 28 and the maps started crashing the app.

Below code within the application element of AndroidManifest.xml for the win!!

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

Upvotes: 1

hsearle
hsearle

Reputation: 73

I spent forever on this, finally stumbled on two things. This goes in your build.gradle for your project (not the app/build.gradle one):

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
    }
}

Just go with your standard react-native settings in your app/build.gradle, don't try and exclude groups in here - this didn't work for me.

This made Android <9.0 work - great. However 9.0+ crashed, not cool. I randomly stumbled upon this information :

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

I really hope this library gets upgraded soon. I hope this helps someone.

Upvotes: 3

Aurangzaib Rana
Aurangzaib Rana

Reputation: 4252

you have open wrong file . go in the Project/android/app/build.gradle open build file and paste the dependencies

Upvotes: 0

Andrew
Andrew

Reputation: 28539

compile was deprecated in favour of implementation. You can easily just replace all instances of the word compile with the word implemenation. So your dependencies would become something like this:

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
}

Upvotes: 1

Related Questions