5

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()
      );
    }
Sarjit Delivala
  • 567
  • 2
  • 13
  • 25
Theodorus Agum Gumilang
  • 1,414
  • 4
  • 23
  • 46

2 Answers2

5

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.

Sarjit Delivala
  • 567
  • 2
  • 13
  • 25
  • Instead of changing the library you can follow this (https://itnext.io/install-react-native-maps-with-gradle-3-on-android-44f91a70a395) – RDD Aug 07 '18 at 11:07
0

Changing a file in the third-party module you're using is probably not the best solution to most problems. It seems that this error is caused because the module has been upgraded to use gradle 3, which is incompatible with the gradle 2 version used by default in react native. There are useful steps to upgrade here: https://github.com/react-native-community/react-native-camera/issues/1490

Jules
  • 14,841
  • 9
  • 83
  • 130