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()
      );
    }
2
  • Just to be sure, have you edited the build.gradlew in the android/app/build.gradle ? Commented Apr 12, 2018 at 11:06
  • Guyz its gradle version issue , please check this stackoverflow answer Commented Jun 9, 2018 at 19:54

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Instead of changing the library you can follow this (itnext.io/…)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.