提问人:m.7.ar 提问时间:5/23/2023 最后编辑:mkrieger1m.7.ar 更新时间:5/23/2023 访问量:1039
如何修复 Gradle 插件 org.jetbrains.kotlin.android 的兼容性问题?“Gradle 插件,凭借其 Kotlin 的优雅,邂逅冲突”
How to fix compatibility issues with Gradle plugin org.jetbrains.kotlin.android? "The Gradle plugin, with its Kotlin grace, Encounters clashes"
问:
我正在使用 Kotlin 和 Gradle,我有这个 buildgradle 应用程序代码:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id("org.jetbrains.kotlin.android") version "1.8.20"
}
android {
namespace 'com.example.loginregisterapp'
compileSdk 33
defaultConfig {
applicationId "com.example.loginregisterapp"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding = true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "io.reactivex.rxjava2:rxjava:2.2.19"
implementation "com.jakewharton.rxbinding2:rxbinding:2.0.0"
implementation platform('com.google.firebase:firebase-bom:32.0.0')
}type here
这是我的build.gradle(项目):
buildscript {
ext.kotlin_version = '1.8.20'
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
// Add the dependency for the Google services Gradle plugin
classpath 'com.google.gms:google-services:4.3.15'
classpath "com.android.tools.build:gradle:8.0.1"
classpath "com.google.gms:google-services:4.3.15"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
task clean (type: Delete){
delete rootProject.buildDir
}
这是我遇到的问题:
Build file 'C:\Users\Gebruiker\Desktop\loginregisterapp\app\build.gradle' line: 4
Error resolving plugin [id: 'org.jetbrains.kotlin.android', version: '1.8.20']
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
我该如何解决这个问题?
答:
0赞
Alex Mamo
5/23/2023
#1
您收到以下错误:
构建文件“C:\Users\Gebruiker\Desktop\loginregisterapp\app\build.gradle”行:4
因为您已在以下代码行中指定了 Kotlin 的版本:
id("org.jetbrains.kotlin.android") version "1.8.20"
在 build.gradle (Module:app) 文件中。没有必要在里面指定,因为你已经在build.gradle(项目)文件中这样做了:plugins
buildscript {
ext.kotlin_version = '1.8.20'
...
}
如果您想在 build.gradle(项目)中定义 Kotlin 的变量,那么您不需要在另一个文件中也这样做。因此,要解决此问题,只需删除版本,错误就会消失:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'org.jetbrains.kotlin.android' //Removed the version
}
评论
0赞
Alex Mamo
6/12/2023
嗨,那里。您是否尝试过我上面的解决方案,它对您有用吗?
评论