Android Studio can't find Kotlin dependency

爷,独闯天下 提交于 2021-01-31 07:21:39

问题


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

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'])
    }
}

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"

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


回答1:


Try this:

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)

// 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
}


来源:https://stackoverflow.com/questions/61025926/android-studio-cant-find-kotlin-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!