Android Compose-Navigation 2.4.0-alpha2 崩溃并出现 NoSuchMethodError

标签 android android-jetpack-compose

更新撰写导航依赖项的版本后,我的应用程序在启动时直接崩溃,并出现以下异常:

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)
...
当使用旧版本时,我得到了 question 中描述的异常。
你有什么想法,什么可能导致这个问题?
这些是我的依赖项(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"
}

最佳答案

你可以试试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"
}

关于Android Compose-Navigation 2.4.0-alpha2 崩溃并出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67836958/

相关文章:

android - 当音频插孔连接或忙碌时在 fragment 内切换图像

Android:在哪里可以找到 Seekbar 可绘制 "scrubber_control_normal_holo"

android - 在与 Coil 的可组合项中使用之前获取位图

android - 撰写导航参数字符串包含大括号吗?

android - Jetpack Compose 开关切换高度

android - Jetpack Compose RememberSwipeableState 回收问题

android - Unity GoogleMobileAdsMediationTestSuite 抛出异常 setAdListener 必须在主 UI 线程上调用

java - 错误的 xml block 3 线性布局和 2 日历

android - 以编程方式添加、删除和设置 CardView 参数

android - Jetpack Compose 格式日期字符串