具有外部依赖关系定义的Gradle DSL中的关闭错误

时间:2016-03-04 17:28:22

标签: android gradle android-gradle build.gradle

在我的gradle文件中,我已将所有依赖关系定义外部化为文件buildsystem/dependencies.gradle

ext {
  //Android
  androidBuildToolsVersion = "23.0.2"
  androidMinSdkVersion = 21
  androidTargetSdkVersion = 23
  androidCompileSdkVersion = 23

  //View libraries
  appcompatVersion = '23.1.1'
  designVersion = '23.1.1'
  //... other dependencies

  //Analytics
  crashlyticsAnswersVersion = '1.3.6'
  crashlyticsCrashlyticsVersion = '2.5.5'

  presentationDependencies = [
        appcompat:            "com.android.support:appcompat-v7:${appcompatVersion}",
        design:               "com.android.support:design:${designVersion}",
        //... other
        answer:               "com.crashlytics.sdk.android:answers:${crashlyticsAnswersVersion}@aar",
        crashlytics:          "com.crashlytics.sdk.android:crashlytics:${crashlyticsCrashlyticsVersion}@aar",
  ]
}

然后,在我的app/build.gradle文件中,我在依赖块中使用了这个定义:

dependencies {
  def presentationDependencies = rootProject.ext.presentationDependencies
  def presentationTestDependencies = rootProject.ext.presentationTestDependencies

  compile presentationDependencies.appcompat
  compile presentationDependencies.design

  compile presentationDependencies.answer {
      transitive = true;
  }
  compile presentationDependencies.crashlytics {
      transitive = true;
  }

  //compile('com.crashlytics.sdk.android:answers:1.3.6@aar') {
  //    transitive = true;
  //}
  //compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
  //    transitive = true;
  //}

  testCompile presentationTestDependencies.junit
}

当以常规方式(注释行)定义Crashlytics依赖项时 - 编译传递。 在我的配置中,我收到了一个错误:

* What went wrong:
A problem occurred evaluating project ':app'.
> No signature of method: java.util.LinkedHashMap.answer() is applicable for argument types:  
(build_3csgketz6zwk5p72to2csf0e$_run_closure3$_closure8) values:
[build_3csgketz6zwk5p72to2csf0e$_run_closure3$_closure8@54bfd47]
Possible solutions: any(), inspect(), use([Ljava.lang.Object;), any(groovy.lang.Closure), any(groovy.lang.Closure)

我该如何定义它?我知道,问题在于封闭包含transitive字段。但我不知道,配置它的正确方法是什么。

1 个答案:

答案 0 :(得分:2)

谢谢@Gabriele Mariotti。

中缺少括号
 compile (presentationDependencies.crashlytics) {
  transitive = true;
 }