AndroidSutido报错:"Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7…"

AndroidStudio升级了个各种更新后,打开之前的项目kotlin代码发现报错了,项目编译也通不过,总提示对kotlin的依赖编译不了,

项目根目录的build.gradle文件中代码如下:

buildscript {
    ext.kotlin_version = '1.3.41'

    repositories {
        google()
        jcenter()
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:3.4.2'
        

    }
}

app目录下build.gradle中如下:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {    ...   }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    implementation 'com.android.support:appcompat-v7:27.1.0'
      

}

最开始的解决思路是不断改kotlin的版本号,但问题得不到解决,后来重新配置了下kotlin的依赖配置解决了

项目根目录的build.gradle文件中代码改为如下:

buildscript {
    ext.kotlin_version = '1.3.41'
    ext.anko_version = "0.9"

    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'

        //手动添加以下两行
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"


    }
}

app目录下build.gradle中改成如下:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {    ...   }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
//    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "org.jetbrains.anko:anko-common:$anko_version"



    implementation 'com.android.support:appcompat-v7:27.1.0'
      

}

重新rebulide一下就好了.

你可能感兴趣的:(android,kotlin)