【问题标题】:Android Studio can't find Kotlin dependencyAndroid Studio 找不到 Kotlin 依赖项
【发布时间】:2020-07-16 10:50:30
【问题描述】:

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

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 文件:

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

以及相关的app gradle依赖:

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

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

【问题讨论】:

    标签: android android-studio gradle kotlin


    【解决方案1】:

    试试这个:

    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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2015-03-24
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多