Compose开发No virtual method at(Ljava/lang/Object;I)错误【已解决】

此问题主要是在用CircularProgressIndicator时报错的,其他没遇到。

在升级不同版本时出现了不少问题,现在记录一下

1、mutableIntStateOf()函数的出现

 要将此条版本更新到2.6.2及以上

implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")

2、更新到ktx1.12时,无明显变化

implementation("androidx.core:core-ktx:1.12.0")

3、添加新依赖

原依赖:

dependencies {

    implementation("androidx.core:core-ktx:1.12.0")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
    implementation("androidx.activity:activity-compose:1.7.0")
    implementation(platform("androidx.compose:compose-bom:2023.03.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

    implementation ("androidx.navigation:navigation-compose:2.6.0-alpha08")
    implementation("androidx.room:room-runtime:2.5.1")
    ksp("androidx.room:room-compiler:2.5.1")
    implementation("androidx.room:room-ktx:2.5.1")
    implementation ("androidx.constraintlayout:constraintlayout-compose:1.0.1")
    implementation ("androidx.activity:activity-ktx:1.8.0-alpha07")
    implementation ("androidx.compose.material3:material3:1.1.2")
    implementation("androidx.wear.compose:compose-material:1.2.1")
    implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.6.2")
}

新添加:

implementation("androidx.compose.foundation:foundation:1.6.0")

3.1关联依赖项1: kotlinCompilerExtensionVersion 

由于添加此项,会导致编译版本变化:

composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }

变为

composeOptions {
        kotlinCompilerExtensionVersion = "1.5.8"
    }

3.2关联依赖项2: compileOptions 和 kotlinOptions 

compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
kotlinOptions {
        jvmTarget = "17"
    }

变为

compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
kotlinOptions {
        jvmTarget = "1.8"
    }

注意以上均在build.gradle.kts(app)中 

3.3关联依赖项3:版本变化

注意这个在build.gradle.kts(Project)中 

plugins {
    id("com.android.application") version "8.1.3" apply false
    id("org.jetbrains.kotlin.android") version "1.8.10" apply false
    id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false
}

变为

plugins {
    id("com.android.application") version "8.1.3" apply false
    id("org.jetbrains.kotlin.android") version "1.9.22" apply false
    id("com.google.devtools.ksp") version "1.9.21-1.0.15" apply false
}

3.4出现问题

FATAL EXCEPTION: main

                                                                                                  java.lang.NoSuchMethodError: No virtual method at(Ljava/lang/Object;I)Landroidx/compose/animation/core/KeyframesSpec$KeyframeEntity;in class Landroidx/compose/animation/core/KeyframesSpec$KeyframesSpecConfig; or its super classes (declaration of 'androidx.compose.animation.core.KeyframesSpec$KeyframesSpecConfig' appears in

此问题主要出现在 ,动态转圈加载,好像是动画出现问题了

CircularProgressIndicator

这个组件中,不清楚其他组件还会不会有问题,看问题主要是androidx.compose.animation出了问题,百度的话说是版本不对,暂时没研究出来啥问题。

3.5 尝试方法

1、app中添加,无效。

implementation(kotlin("stdlib-jdk8"))

2、添加animation,无效

implementation("androidx.compose.animation:animation:1.6.0")

3、添加无效

implementation("androidx.compose.runtime:runtime:1.6.0")
    implementation("androidx.compose.runtime:runtime-livedata:1.6.0")

4、添加无效

implementation("androidx.compose.ui:ui:1.6.0")

5.更新,无效但采用,因为要和上面的版本对上

id("com.google.devtools.ksp") version "1.9.22-1.0.16" apply false

4、问题解决

在StackOverflow上找到了一模一样的问题(知道有问题去哪了吧),解决方法如下:

更新material3的版本

    implementation ("androidx.compose.material3:material3-android:1.2.0-rc01")

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