gradle - 尝试将木材添加到Kotlin项目中会导致多个 'Unable to resolve dependency for…' Gradle错误

标签 gradle kotlin android-gradle-plugin timber-android

我已经将implementation 'com.jakewharton.timber:timber:4.7.1'添加到我的Kotlin项目中,现在出现以下Gradle错误:

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details

奇怪的是,尽管我可以看到它随着Gradle同步下载:

enter image description here

我也尝试添加timberkt,但出现类似错误。

我的整个app/build.gradle文件如下所示:
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlinx-serialization'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "uk.co.davechambers.pegboard"
    targetSdkVersion 26
    minSdkVersion 21
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary= true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
google()
jcenter()
    maven { url "https://kotlin.bintray.com/kotlinx" }
   }

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.0.0-beta2'
implementation 'com.jakewharton.timber:timber:4.7.1'
compile "org.jetbrains.anko:anko:$anko_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
}

 kotlin {
experimental {
    coroutines "enable"
}
  }

androidExtensions {
experimental = true
}

显然我做错了。有人能指出我正确的方向吗?

最佳答案

我在build.gradle (Module: app)中添加了一个额外的Maven网址:

repositories {
    google()
    jcenter()
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "http://jcenter.bintray.com"}
}

build.gradle (Project: projectName):
buildscript {
    ext.kotlin_version = '1.2.40'
    ext.anko_version = '0.10.5'
    ext.serialization_version = '0.4.1'
    repositories {
        google()
        jcenter()
        maven { url "https://kotlin.bintray.com/kotlinx" }
        maven { url "http://jcenter.bintray.com"}
    }
.....

之后,一切正常。

关于gradle - 尝试将木材添加到Kotlin项目中会导致多个 'Unable to resolve dependency for…' Gradle错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51570737/

相关文章:

Gradle:如何将绝对路径列表复制到单个目录中

android - 如何使android忽略布局预览的特定代码

java - 如何向 EditTextPreference 添加消息?

java - 如何在我的 list 中正确设置多个 applicationIds 或包名称

gradle - 将 gradle 临时缓存目录移动到其他目录

testing - Gradle jetty 运行: how does this thing work?

android - 项目不会使用 Kotlin 1.1.3 构建

android - 当 Android 测试失败时,Gradle 构建失败并显示 "String Index out of range"

gradle - 升级到android gradle插件3.0.0+后,项目无法构建

java - 如何自动将 'implementation' 行添加到新项目