Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using Maps in react native

I want to use maps in my react native app. So I installed react-native-maps from airbnb, but when I try to build the apps it always shows this error "Could not find method compileOnly() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler." , I already set up the build gradle, the setting gradle, and the MainApllication. Can anyone help me in here? My Build.Gradle

dependencies {
    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:10.0.1'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

My Setting.Gradle

rootProject.name = 'MapDemo'
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
include ':app'

My MainApplication.Java

import com.airbnb.android.react.maps.MapsPackage;
 @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
           new MapsPackage()
      );
    }
like image 671
Theodorus Agum Gumilang Avatar asked Apr 12 '18 10:04

Theodorus Agum Gumilang


People also ask

Is Google Maps free for react-native?

"Embedding Google Maps through react-native-maps does require an API key, but it is at no cost.

What is react-native maps?

react-native-maps provides a Map component that uses Apple Maps or Google Maps on iOS and Google Maps on Android. Expo uses react-native-maps at react-native-maps/react-native-maps. No setup required for use within the Expo Go app.


1 Answers

I faced a similar issue and found the solution from here:

Navigate to node_modules/react-native-maps/lib/android/build.gradle and then change compileOnly to provided and implementation to compile.

I hope this helps.

like image 170
Sarjit Delivala Avatar answered Oct 18 '22 21:10

Sarjit Delivala