Compose Complier(Compose编译器)和Kotlin版本的兼容性。

huangapple go评论79阅读模式
英文:

Compose Complier & Kotlin Version Compatibility

问题

所以我在升级项目后无法使我的应用程序正常工作。

我遇到了以下错误:

> Task :app:compileDebugKotlin FAILED
e: This version (1.0.3) of the Compose Compiler requires Kotlin version 1.5.30 but you appear to be using Kotlin version 1.8.20 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).

我已经安装了最新版本的插件(223-1.8.0-release-345-AS8836.35.2231.10406996)在Android Studio Giraffe 2022.3.1上,但我无法解决这个问题。

这是我的完整build.gradle(:app):

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.0.3'
        kotlinCompilerVersion '1.5.30'
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    namespace '__________'
    compileSdk 33

    defaultConfig {
        applicationId "___________"
        minSdk 30
        targetSdkVersion 33
        versionCode 1
        versionName "1.0.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        // Enabling multidex support.
        multiDexEnabled true
        vectorDrawables{
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            minifyEnabled true // https://www.youtube.com/watch?v=EOQB8PTLkpY&list=PLWz5rJ2EKKc9Ty3Zl1hvMVUsXfkn93NRk
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    // Added for MVVM: https://www.simplifiedcoding.net/firebase-mvvm-example/
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation 'androidx.activity:activity-compose:1.7.2'
    implementation 'androidx.activity:activity-ktx:1.7.2'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.appcompat:appcompat-resources:1.6.1'
    implementation 'androidx.core:core-ktx:1.10.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    // Lifecycle
    implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.1"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.1"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1" //https://www.simplifiedcoding.net/firebase-mvvm-example/

    // Compose
    implementation platform('androidx.compose:compose-bom:2023.06.01')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview:1.4.3'
    implementation 'androidx.compose.material3:material3:1.1.1'
    implementation "androidx.compose.material:material-icons-extended"
    implementation 'androidx.compose.material:material:1.4.3'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

    debugImplementation 'androidx.compose.ui:ui-tooling:1.4.3'
    debugImplementation 'androidx.compose.ui:ui-test-manifest:1.4.3'

    // Navigation
    implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'

    // Testing
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    testImplementation 'junit:junit:4.13.2'

    // Add the SDKs for any other Firebase products you want to use in your app
    // For example, to use Firebase Authentication and Cloud Firestore
    implementation 'com.google.firebase:firebase-firestore:24.7.0'
    implementation 'com.google.firebase:firebase-auth:22.1.1'
    implementation 'com.google.firebase:firebase-messaging:23.2.1'
    implementation 'com.google.firebase:firebase-core:21.1.1'
    implementation 'com.google.firebase:firebase-storage:20.2.1'
    implementation 'com.google.android.gms:play-services-auth:20.6.0'

    // Add the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-analytics:21.3.0'

//    // Picasso
//    implementation 'com.squareup.picasso:picasso:2.71828'

    //anko https://www.youtube.com/watch?v=uB7WeED1d1w
//    implementation "org.jetbrains.anko:anko:0.10.4"
//    implementation "org.jetbrains.anko:anko-design:0.10.4"
//    implementation "org.jetbrains.anko:anko-coroutines:0.10.4"

    // Material Dialogs (https://github.com/afollestad/material-dialogs, recommended by CodingWithMitch https://www.youtube.com/watch?v=_sOHZAk6KnA)
    implementation 'com.afollestad.material-dialogs:core:3.3.0'
    implementation 'com.afollestad.material-dialogs:input:3.3.0'
    implementation 'com.afollestad.material-dialogs:datetime:3.3.0'
    implementation 'com.afollestad.material-dialogs:lifecycle:3.3.0'

    // debugImplementation because LeakCanary should only run in debug builds.
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'

    // Couroutines Dependency
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
}

这是我的完整build.gradle(Project):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
        classpath 'com.android.tools.build:gradle:8.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://developer.android.com/studio/build/repository' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
英文:

So I am struggling to get my app to work after upgrading my project.

I am getting the following error:

> Task :app:compileDebugKotlin FAILED
e: This version (1.0.3) of the Compose Compiler requires Kotlin version 1.5.30 but you appear to be using Kotlin version 1.8.20 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).

I have the latest version of the plugin installed (223-1.8.0-release-345-AS8836.35.2231.10406996) on Android Studio Giraffe 2022.3.1, but I cannot get this to go away.

Here is my full build.gradle(:app):

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

plugins {
id &#39;com.android.application&#39;
id &#39;org.jetbrains.kotlin.android&#39;
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion &#39;1.0.3&#39;
kotlinCompilerVersion &#39;1.5.30&#39;
}
kotlinOptions {
jvmTarget = &quot;1.8&quot;
}
namespace &#39;__________&#39;
compileSdk 33
defaultConfig {
applicationId &quot;___________&quot;
minSdk 30
targetSdkVersion 33
versionCode 1
versionName &quot;1.0.0&quot;
testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
// Enabling multidex support.
multiDexEnabled true
vectorDrawables{
useSupportLibrary = true
}
}
buildTypes {
release {
minifyEnabled true // https://www.youtube.com/watch?v=EOQB8PTLkpY&amp;list=PLWz5rJ2EKKc9Ty3Zl1hvMVUsXfkn93NRk
proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = &quot;17&quot;
}
// Added for MVVM: https://www.simplifiedcoding.net/firebase-mvvm-example/
dataBinding {
enabled = true
}
}
dependencies {
implementation &#39;androidx.activity:activity-compose:1.7.2&#39;
implementation &#39;androidx.activity:activity-ktx:1.7.2&#39;
implementation &#39;androidx.appcompat:appcompat:1.6.1&#39;
implementation &#39;androidx.appcompat:appcompat-resources:1.6.1&#39;
implementation &#39;androidx.core:core-ktx:1.10.1&#39;
implementation fileTree(dir: &#39;libs&#39;, include: [&#39;*.jar&#39;])
implementation &#39;androidx.multidex:multidex:2.0.1&#39;
implementation &#39;androidx.legacy:legacy-support-v4:1.0.0&#39;
// Lifecycle
implementation &quot;androidx.lifecycle:lifecycle-runtime-compose:2.6.1&quot;
implementation &quot;androidx.lifecycle:lifecycle-runtime-ktx:2.6.1&quot;
implementation &quot;androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1&quot;
implementation &quot;androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1&quot;
implementation &quot;androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.1&quot;
implementation &quot;androidx.lifecycle:lifecycle-runtime-ktx:2.6.1&quot; //https://www.simplifiedcoding.net/firebase-mvvm-example/
// Compose
implementation platform(&#39;androidx.compose:compose-bom:2023.06.01&#39;)
implementation &#39;androidx.compose.ui:ui&#39;
implementation &#39;androidx.compose.ui:ui-graphics&#39;
implementation &#39;androidx.compose.ui:ui-tooling-preview:1.4.3&#39;
implementation &#39;androidx.compose.material3:material3:1.1.1&#39;
implementation &quot;androidx.compose.material:material-icons-extended&quot;
implementation &#39;androidx.compose.material:material:1.4.3&#39;
implementation &#39;androidx.cardview:cardview:1.0.0&#39;
implementation &#39;androidx.constraintlayout:constraintlayout:2.1.4&#39;
debugImplementation &#39;androidx.compose.ui:ui-tooling:1.4.3&#39;
debugImplementation &#39;androidx.compose.ui:ui-test-manifest:1.4.3&#39;
// Navigation
implementation &#39;androidx.navigation:navigation-fragment-ktx:2.6.0&#39;
implementation &#39;androidx.navigation:navigation-ui-ktx:2.6.0&#39;
// Testing
androidTestImplementation &#39;androidx.test.ext:junit:1.1.5&#39;
androidTestImplementation &#39;androidx.test.espresso:espresso-core:3.5.1&#39;
testImplementation &#39;junit:junit:4.13.2&#39;
// Add the SDKs for any other Firebase products you want to use in your app
// For example, to use Firebase Authentication and Cloud Firestore
implementation &#39;com.google.firebase:firebase-firestore:24.7.0&#39;
implementation &#39;com.google.firebase:firebase-auth:22.1.1&#39;
implementation &#39;com.google.firebase:firebase-messaging:23.2.1&#39;
implementation &#39;com.google.firebase:firebase-core:21.1.1&#39;
implementation &#39;com.google.firebase:firebase-storage:20.2.1&#39;
implementation &#39;com.google.android.gms:play-services-auth:20.6.0&#39;
// Add the Firebase SDK for Google Analytics
implementation &#39;com.google.firebase:firebase-analytics:21.3.0&#39;
//    // Picasso
//    implementation &#39;com.squareup.picasso:picasso:2.71828&#39;
//anko https://www.youtube.com/watch?v=uB7WeED1d1w
//    implementation &quot;org.jetbrains.anko:anko:0.10.4&quot;
//    implementation &quot;org.jetbrains.anko:anko-design:0.10.4&quot;
//    implementation &quot;org.jetbrains.anko:anko-coroutines:0.10.4&quot;
// Material Dialogs (https://github.com/afollestad/material-dialogs, recommended by CodingWithMitch https://www.youtube.com/watch?v=_sOHZAk6KnA)
implementation &#39;com.afollestad.material-dialogs:core:3.3.0&#39;
implementation &#39;com.afollestad.material-dialogs:input:3.3.0&#39;
implementation &#39;com.afollestad.material-dialogs:datetime:3.3.0&#39;
implementation &#39;com.afollestad.material-dialogs:lifecycle:3.3.0&#39;
// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation &#39;com.squareup.leakcanary:leakcanary-android:2.12&#39;
// Couroutines Dependency
implementation &#39;org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3&#39;
}

<!-- end snippet -->

This is my full build.gradle(Project):

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath &#39;com.google.gms:google-services:4.3.15&#39;
classpath &#39;androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0&#39;
classpath &#39;org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21&#39;
classpath &#39;com.android.tools.build:gradle:8.1.0&#39;
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url &#39;https://developer.android.com/studio/build/repository&#39; }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

<!-- end snippet -->

答案1

得分: 2

根据这个链接,你会知道你的编译器版本应该与 Kotlin 版本匹配。你正在使用 Kotlin 版本 1.8.20,在构建文件中将 Compose 编译器更改为 1.4.5。

composeOptions {
    kotlinCompilerExtensionVersion = "1.4.5"
}
英文:

Following this link you will know that your compiler version should match with the kotlin version. You are using kotlin version 1.8.20 ,in the build file change the compose compiler to 1.4.5

   composeOptions {
kotlinCompilerExtensionVersion = &quot;1.4.5&quot;
}

huangapple
  • 本文由 发表于 2023年8月9日 02:23:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76862250.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定