Android Compose-Navigation 2.4.0-alpha2 崩溃并显示 NoSuchMethodError

7
更新了compose navigation依赖版本后,我的应用程序在启动时直接崩溃,并抛出以下异常:
java.lang.NoSuchMethodError: No static method drawRect-w2WG-Gw$default(Landroidx/compose/ui/graphics/drawscope/DrawScope;JJJFLandroidx/compose/ui/graphics/drawscope/DrawStyle;Landroidx/compose/ui/graphics/ColorFilter;Landroidx/compose/ui/graphics/BlendMode;ILjava/lang/Object;)V in class Landroidx/compose/ui/graphics/drawscope/DrawScope$DefaultImpls; or its super classes (declaration of 'androidx.compose.ui.graphics.drawscope.DrawScope$DefaultImpls' appears in /data/app/~~pBKRwWSGSd6Trycrlz_8bw==/com.example.wunderguard-9YsObT0GJC9oUzrTLizqog==/base.apk)
    at androidx.compose.foundation.Background.drawRect(Background.kt:111)
    at androidx.compose.foundation.Background.draw(Background.kt:103)
...

使用旧版时,我遇到了这个问题中描述的异常。

你有什么想法,可能是什么原因导致了这个问题?这是我的依赖项(compose_version = '1.0.0-beta07')。

dependencies {

implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.navigation:navigation-compose:2.4.0-alpha02"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation "androidx.activity:activity-compose:1.3.0-beta01"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"

}


肯定问题出在alpha2 :D - Eugene Troyanskii
你能试试beta08吗? - Gabriele Mariotti
更新Compose到beta08和Kotlin到1.5.10之后,它可以工作了!谢谢你的提示,我没有意识到已经有beta08了 :/ - jpm
4个回答

15

您可以尝试使用1.0.0-beta09并更新 Kotlin 编译器至1.5.10,此配置

    kotlinOptions {
        jvmTarget = '1.8'
        useIR = true
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion "1.0.0-beta08"
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.5.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    

    // Compose
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.0.0-beta08"
    implementation "androidx.activity:activity-compose:1.3.0-beta02"
    implementation "androidx.compose.runtime:runtime:1.0.0-beta09"
    implementation "androidx.compose.ui:ui:1.0.0-beta09"
    implementation "androidx.compose.foundation:foundation:1.0.0-beta09"
    implementation "androidx.compose.foundation:foundation-layout:1.0.0-beta09"
    implementation "androidx.compose.material:material:1.0.0-beta09"
    implementation "androidx.compose.runtime:runtime-livedata:1.0.0-beta09"
    implementation "androidx.compose.ui:ui-tooling:1.0.0-beta09"
    implementation "com.google.android.material:compose-theme-adapter:1.0.0-beta09"
}

1
更新Compose到beta08和Kotlin到1.5.10之后,它可以工作了!感谢提示,我没有意识到已经有beta08了... - jpm

4

0

androidx.navigation:navigation-compose在beta版本中不可用。根据(https://developer.android.com/jetpack/androidx/releases/navigation#version_240_2)的说法,它应该与Compose beta 07及以上版本兼容...Compose兼容性 androidx.navigation:navigation-compose:2.4.0-alpha01仅与Compose版本1.0.0-beta07及以上版本兼容。 - jpm

0

将Compose更新到beta08版本,Kotlin更新到1.5.10版本,问题得到了解决!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接