解决失败:多模块Kotlin项目的org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.71错误

时间:2018-09-27 19:17:07

标签: android gradle kotlin

我正在使用Android Studio 3.2版,并且具有多模块Gradle构建。

我有一个名为dependencies.gradle的文件,看起来像这样:

   ext{
  //Android
  androidBuildToolsVersion = "26.0.0"
  androidMinSdkVersion = 21
  androidTargetSdkVersion = 26
  androidCompileSdkVersion = 26
  kotlinVersion = '1.2.71'

  //Libraries
  supportLibraryVersion = '26.1.0'
  rxJavaVersion = '2.2.0'
  javaxAnnotationVersion = '1.0'
  javaxInjectVersion = '1'
  rxKotlinVersion = '2.2.0'
  androidAnnotationsVersion='21.0.3'
  daggerVersion = '2.14.1'


  //Testing
  jUnitVersion = '4.12'
  assertJVersion = '3.11.0'
  mockitoKotlinVersion ='2.0.0-RC2'
  robolectricVersion = '3.4.2'

  domainDependencies = [
      javaxAnnotation: "javax.annotation:jsr250-api:${javaxAnnotationVersion}",
      javaxInject: "javax.inject:javax.inject:${javaxInjectVersion}",
      rxJava: "io.reactivex.rxjava2:rxkotlin:${rxJavaVersion}"
  ]

  domainTestDependencies = [
      junit: "junit:junit:${jUnitVersion}",
      mockito: "com.nhaarman.mockitokotlin2:mockito-kotlin:${mockitoKotlinVersion}",
      assertj: "org.assertj:assertj-core:${assertJVersion}"
  ]

  dataDependencies = [
      rxKotlin: "io.reactivex.rxjava2:rxkotlin:${rxKotlinVersion}",
      javaxAnnotation: "javax.annotation:jsr250-api:${javaxAnnotationVersion}",
       kotlin:    "org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}",
      javaxInject: "javax.inject:javax.inject:${javaxInjectVersion}",
  ]

  dataTestDependencies = [
      junit: "junit:junit:${jUnitVersion}",
      kotlinJUnit: "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}",
      mockito: "com.nhaarman.mockitokotlin2:mockito-kotlin:${mockitoKotlinVersion}",
      assertj: "org.assertj:assertj-core:${assertJVersion}",
      robolectric: "org.robolectic:robolectric:${robolectricVersion}"
  ]

}

我想在我的应用中为数据模块编写测试,而我对数据模块的build.gradle如下。

apply plugin: 'kotlin'

dependencies {
    compile project(':Domain')

    def dataDependencies = rootProject.ext.dataDependencies
    def dataTestDependencies = rootProject.ext.dataTestDependencies



    implementation dataDependencies.javaxAnnotation
    implementation dataDependencies.javaxInject
    implementation dataDependencies.rxKotlin
    implementation dataDependencies.kotlin

    testImplementation dataTestDependencies.junit
    testImplementation dataTestDependencies.mockito
    testImplementation dataTestDependencies.assertj
    testImplementation dataTestDependencies.kotlinJUnit


}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

但是当我同步Gradle文件时,我从Android Studio中收到以下错误消息。

  • Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.71
  • Failed to resolve: org.jetbrains.kotlin:kotlin-test-junit:1.2.71

真的很感谢您的帮助,因为我确定我使用了正确的软件包名称。预先感谢

1 个答案:

答案 0 :(得分:1)

将此添加到app文件夹中的build.gradle 实现组:“ org.jetbrains.kotlin”,名称:“ kotlin-stdlib”,版本:“ 1.2.0” 这样就解决了我的问题。

在您的情况下,请更改版本:实现组:“ org.jetbrains.kotlin”,名称:“ kotlin-stdlib”,版本:“ 1.2.71”