【发布时间】:2018-04-12 10:26:15
【问题描述】:
我想在我的 react 原生应用中使用地图。所以我从 airbnb 安装了 react-native-maps,但是当我尝试构建应用程序时,它总是显示此错误 "Could not find method compileOnly() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler." ,我已经设置了构建 gradle、设置 gradle 和 MainApllication。任何人都可以在这里帮助我吗?
我的 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
}
我的设置.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'
我的 MainApplication.Java
import com.airbnb.android.react.maps.MapsPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MapsPackage()
);
}
【问题讨论】:
-
为了确定,您是否编辑了
android/app/build.gradle中的build.gradlew? -
Guyz 的 gradle 版本问题,请查看stackoverflow answer
标签: android reactjs google-maps react-native