簡體   English   中英

Android Studio:無法獲取未知屬性“kotlin_version”

[英]Android Studio : Could not get unknown property 'kotlin_version'

這里git 克隆后,

我第一次遇到這個錯誤:

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\...\voicegym\app\build.gradle' line: 3

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not initialize class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt

按照這個建議,我將這些添加到build.gradle (Project: voicegym)

buildscript {
    ext.kotlinVersion = '1.3.72' // previously  '1.2.60'
    ext.springBootVersion = '2.0.4.RELEASE'
    ext.anko_version='0.10.4'
    repositories {
        ...
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

現在,我有這個錯誤

Build file 'C:\...\voicegym\build.gradle' line: 5

A problem occurred evaluating root project 'voicegym'.
> Could not get unknown property 'kotlin_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

經過實驗,應該是ext.kotlin_version=...而不是ext.kotlinVersion =...

buildscript {
    ext.kotlin_version= '1.3.72' // previously  '1.2.60'
    ext.springBootVersion = '2.0.4.RELEASE'
    ext.anko_version='0.10.4'
    repositories {
        ...
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

在 android/build.gradle 文件中放置以下代碼:

buildscript {
ext.kotlin_version = '1.5.31'
repositories {
    google()
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:7.0.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 }
}

在 app/build.gradle 文件中放置以下代碼:

dependencies {
 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

只需像這樣添加 ext.kotlin_version="1.3.72"

buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {

錯誤將明確解決

修復此錯誤所需要做的就是在“Android/build.gradle(Project:projectName) 文件中的ext組件中添加以下行:

kotlin_version = '1.5.31'

ext組件將如下所示:

ext {
activityVersion = '1.4.0'
appCompatVersion = '1.4.0'
constraintLayoutVersion = '2.1.2'
coreTestingVersion = '2.1.0'
coroutines = '1.5.2'
lifecycleVersion = '2.4.0'
materialVersion = '1.4.0'
roomVersion = '2.3.0'
// testing
junitVersion = '4.13.2'
espressoVersion = '3.4.0'
androidxJunitVersion = '1.1.3'
 //Add the kotlin version here:
kotlin_version = '1.5.31'

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM