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()
);
}
"Embedding Google Maps through react-native-maps does require an API key, but it is at no cost.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With