【问题标题】:Error when using Maps in react native在本机反应中使用地图时出错
【发布时间】: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


【解决方案1】:

我遇到了类似的问题,并从here找到了解决方案:

导航到node_modules/react-native-maps/lib/android/build.gradle,然后 将compileOnly 更改为provided 并将implementation 更改为compile

我希望这会有所帮助。

【讨论】:

【解决方案2】:

更改您正在使用的第三方模块中的文件可能不是大多数问题的最佳解决方案。看来这个错误是因为模块已经升级到使用gradle 3,与react native默认使用的gradle 2版本不兼容。这里有有用的升级步骤:https://github.com/react-native-community/react-native-camera/issues/1490

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 2020-03-25
    • 2020-09-30
    • 2019-10-01
    相关资源
    最近更新 更多