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

文章讲述了在使用CircularProgressIndicator时遇到的问题,涉及版本升级(如从2.6.2到1.9.22)、kotlin编译器扩展版本调整以及动画库的兼容性问题。作者尝试了多种解决方案后,发现更新material3版本解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

此问题主要是在用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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HO灵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值