【问题标题】:Android Compose-Navigation 2.4.0-alpha2 crashes with NoSuchMethodErrorAndroid Compose-Navigation 2.4.0-alpha2 崩溃并出现 NoSuchMethodError
【发布时间】:2021-06-04 12:07:29
【问题描述】:

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

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"

}

【问题讨论】:

  • 确定问题出在 alpha2 中:D
  • 可以试试 beta08 吗?
  • 将 Compose 更新到 beta08 并将 Kotlin 更新到 1.5.10 后,它可以工作了!感谢您的提示,我没有意识到已经有 beta08:/

标签: android android-jetpack-compose


【解决方案1】:

您可以尝试使用 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"
}

【讨论】:

  • 将 Compose 更新到 beta08 并将 Kotlin 更新到 1.5.10 后,它可以工作了!感谢您的提示,我没有意识到已经有 beta08...
【解决方案2】:

版本androidx.navigation:navigation-compose:2.4.0-alpha02 包含此提交:

Upgrade to Kotlin 1.5.0, KSP to 1.5.0-1.0.0-alpha09

  • 将您的撰写依赖项更新为 1.0.0-beta08
  • 将 Kotlin 编译器更新为 1.5.10

【讨论】:

    【解决方案3】:

    您阅读您发布的链接吗? java.lang.NoSuchMethodError after upgrading Jetpack Compose to 1.0.0‑beta07? Obviouse 必须为所有 compose 库使用相同的版本。

    【讨论】:

    • androidx.navigation:navigation-compose 在测试版中不可用。根据 (developer.android.com/jetpack/androidx/releases/…) 它应该适用于 compose beta 07 及更高版本... Compose 兼容性 androidx.navigation:navigation-compose:2.4.0-alpha01 仅与 Compose 1.0.0-beta07 及更高版本兼容。跨度>
    【解决方案4】:

    将 Compose 更新到 beta08 并将 Kotlin 更新到 1.5.10 为我解决了这个问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多