Android Studio 找不到 Kotlin 依赖 [英] Android Studio can't find Kotlin dependency

查看:294
本文介绍了Android Studio 找不到 Kotlin 依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图升级我的 Android Studio 项目的一些依赖项,现在每当我尝试构建项目时,我都会遇到此错误消息:

I was trying to upgrade some dependencies for my Android Studio project and now I'm stuck with this error message whenever I try to build the project:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugAnnotationProcessorClasspath'.
   > Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.60-eap-25.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.60-eap-25/kotlin-stdlib-jdk8-1.3.60-eap-25.pom
       - https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.60-eap-25/kotlin-stdlib-jdk8-1.3.60-eap-25.pom
     Required by:
         project :app > androidx.databinding:databinding-compiler:4.0.0-alpha04
         project :app > androidx.databinding:databinding-compiler:4.0.0-alpha04 > androidx.databinding:databinding-compiler-common:4.0.0-alpha04

这是我的项目 gradle 文件:

Here's my project gradle file:

buildscript {
    // Define versions in a single place
    ext {
        // Sdk and tools
        compileSdkVersion = 28
        minSdkVersion = 21
        targetSdkVersion = 28

        // App dependencies
        appCompatVersion = '1.1.0'
        fragmentVersion = '1.2.3'
        gradleVersion = '4.0.0-alpha04'
        kotlinVersion = '1.3.60-eap-25'
        ktlintVersion = '0.33.0'
        ktxVersion = '1.2.0'
        mapVersion = '17.0.0'
    }

    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap'}
    }

    dependencies {
        classpath "com.android.tools.build:gradle:${gradleVersion}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
    }
}

plugins {
    id "com.diffplug.gradle.spotless" version "3.24.0"
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

spotless {
    kotlin {
        target "**/*.kt"
        ktlint(ktlintVersion).userData(['max_line_length' : '100'])
    }
}

以及相关的应用gradle依赖:

And the relevant app gradle dependencies:

kaptTest "androidx.databinding:databinding-compiler:$gradleVersion"
implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"

我尝试过使用其他 Kotlin 版本,但这样做时我什至无法同步 gradle 文件.

I've tried using other Kotlin versions but I can't even sync the gradle files when I do that.

推荐答案

试试这个:

build.gradle(:app)

build.gradle(:app)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.example.mytestapplication"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.core:core:1.3.0-alpha02'
    implementation 'androidx.mediarouter:mediarouter:1.1.0'
}

build.gradle(:projectname)

build.gradle(:projectname)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这篇关于Android Studio 找不到 Kotlin 依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆