You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

签名Debug构建出现java.lang.NoSuchMethodError问题求助

解决签名Debug构建中Compose RowScope.weight方法找不到的问题

问题场景

  • 仅签名Debug构建触发java.lang.NoSuchMethodError,普通Debug、Release构建运行正常
  • 异常来自第三方头部组件库,核心错误:
    java.lang.NoSuchMethodError: No static method weight$default(Landroidx/compose/foundation/layout/RowScope;Landroidx/compose/ui/Modifier;FZILjava/lang/Object;)Landroidx/compose/ui/Modifier; in class Landroidx/compose/foundation/layout/RowScope;
    

完整错误堆栈

2022-10-06 12:18:45.105 28649-28649/com.xxx.xxxxx E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx.xxxxx, PID: 28649
    java.lang.NoSuchMethodError: No static method weight$default(Landroidx/compose/foundation/layout/RowScope;Landroidx/compose/ui/Modifier;FZILjava/lang/Object;)Landroidx/compose/ui/Modifier; in class Landroidx/compose/foundation/layout/RowScope; or its super classes (declaration of 'androidx.compose.foundation.layout.RowScope' appears in /data/app/com.xxx.xxxxx-YA6SxY30QsTUjhr6DzpFHg==/base.apk)
        at com.ads.ds.compose.header.HeaderKt.JDSHeader(Header.kt:205)
        at com.xxx.xxxxx.header.MyAppJDSHeader.SetJDSHeader(MyAppJDSHeader.kt:59)
        at com.xxx.xxxxx.header.MyAppJDSHeader.MyAppJdsHeader(MyAppJDSHeader.kt:49)
        at com.xxx.xxxxx.dashboard.activities.DashboardActivity$setComposeHeader$1$invoke$$inlined$MyAppJdsTheme$1.invoke(MyAppJdsTheme.kt:57)
        at com.xxx.xxxxx.dashboard.activities.DashboardActivity$setComposeHeader$1$invoke$$inlined$MyAppJdsTheme$1.invoke(MyAppJdsTheme.kt:32)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.material.MaterialTheme_androidKt.PlatformMaterialTheme(MaterialTheme.android.kt:23)
        at androidx.compose.material.MaterialThemeKt$MaterialTheme$1$1.invoke(MaterialTheme.kt:82)
        at androidx.compose.material.MaterialThemeKt$MaterialTheme$1$1.invoke(MaterialTheme.kt:81)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.material.TextKt.ProvideTextStyle(Text.kt:265)
        at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:81)
        at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:80)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.material.MaterialThemeKt.MaterialTheme(MaterialTheme.kt:72)
        at com.ads.ds.compose.themes.JdsThemeKt$JdsTheme$1.invoke(JdsTheme.kt:11)
        at com.ads.ds.compose.themes.JdsThemeKt$JdsTheme$1.invoke(JdsTheme.kt:10)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at com.ads.ds.compose.themes.JdsThemeKt.ProvideJdsThemeColors(JdsTheme.kt:29)
        at com.ads.ds.compose.themes.JdsThemeKt.JdsTheme(JdsTheme.kt:10)
        at com.xxx.xxxxx.dashboard.activities.DashboardActivity$setComposeHeader$1.invoke(DashboardActivity.kt:8286)
        at com.xxx.xxxxx.dashboard.activities.DashboardActivity$setComposeHeader$1.invoke(DashboardActivity.kt:1230)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:402)
        at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:248)
        at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:247)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
2022-10-06 12:18:45.114 28649-28649/com.xxx.xxxxx E/AndroidRuntime:     at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:177)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:157)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:156)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:156)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:74)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3193)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3183)
        at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:252)
        at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
        at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3183)
        at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3119)
        at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:584)
        at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:811)
        at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1015)
        at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:182)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
        at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:202)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:138)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1102)
        at android.view.View.dispatchAttachedToWindow(View.java:19678)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3455)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
2022-10-06 12:18:45.114 28649-28649/com.xxx.xxxxx E/AndroidRuntime:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)

解决方案

1. 统一Compose依赖版本

项目中所有Compose相关依赖(foundation、ui、material等)必须使用完全一致的版本,避免第三方库与本地依赖的版本冲突:

  • 在项目根build.gradle中定义统一版本变量:
    ext {
        compose_version = "1.3.1" // 替换为你项目使用的稳定版本
    }
    
  • 所有模块的Compose依赖引用该变量,例如:
    implementation "androidx.compose.foundation:foundation:$compose_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    

2. 检查签名Debug构建的混淆配置

签名Debug构建可能误开启了代码压缩,导致Compose关键方法被移除:

  • 打开模块的build.gradle,检查debug闭包配置:
    debug {
        signingConfig signingConfigs.debug
        // 确保代码压缩和资源压缩关闭
        minifyEnabled false
        shrinkResources false
    }
    
  • 如果必须开启混淆,在proguard-rules.pro中添加规则保留Compose方法:
    -keep class androidx.compose.foundation.layout.RowScope { *; }
    -keepclassmembers class androidx.compose.foundation.layout.RowScope { *; }
    

3. 清理缓存并重建项目

执行以下命令清理gradle缓存,避免旧依赖残留:

./gradlew clean
./gradlew assembleDebug

4. 验证第三方库兼容性

确认第三方头部组件库支持你项目使用的Compose版本,若版本差距过大,考虑升级第三方库或降级Compose到兼容版本。

5. 配置R8兼容规则(若使用R8)

如果项目启用了R8优化,添加以下配置确保Compose默认方法不被移除:

  • 在模块build.gradle中启用核心库脱糖:
    android {
        buildTypes {
            debug {
                compileOptions {
                    coreLibraryDesugaringEnabled true
                }
            }
        }
    }
    
  • 在proguard-rules.pro中添加:
    -keepclassmembers class kotlin.Metadata {
        public <methods>;
    }
    -keepclassmembers class androidx.compose.foundation.layout.RowScope {
        public static ** weight$default(...);
    }
    

内容的提问来源于stack exchange,提问作者Ankush

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 12:45:29