This is a quick tutorial on how to properly install react-native-maps with gradle 3 without breaking your app.

So I’ve tried to install react-native-maps (I’ve installed the lastet version 0.21.0 ) on Android and unfortunately I wasn’t able to make it work. When running react-native run-android , the build fails and returns this error:

error while run android in(Could not find method compileOnly() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.)

Even if you correctly followed the official installation guide of react-native-maps it would still not work. So after a few research, trial and error I was able to find a solution to make react-native-maps work.

Let’s start with . . .

How to install react-native-maps properly

Installation

Install react-native-maps library.

# using yarn yarn add react-native-maps # using npm npm install react-native-maps --save

2. Link react-native-maps to your project by running:

react-native link

3. In your android/app/build.gradle replace the contents of dependencies with:

dependencies { implementation fileTree(dir: "libs", include: ["*.jar"])

implementation "com.android.support:appcompat-v7:23.0.1"

implementation "com.facebook.react:react-native:+"

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

implementation 'com.google.android.gms:play-services-maps:10.0.1' }

The syntax compile is for gradle version 2. Since react-native-maps now uses gradle version 3, we have to update compile to implementation in order to make it work.

4. Specify your Google Maps API Key. Add your API key to your manifest file in android/app/src/main/AndroidManifest.xml :

<application>

<!-- You will only need to add this meta-data tag, but make sure it's a child of application --> <meta-data

android:name="com.google.android.geo.API_KEY"

android:value="Your Google maps API Key Here"/> </application>