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

构建签名Gradle APK时遇google.android.gms.internal.zzelh方法引用错误求助

解决签名Gradle APK构建时的Proguard方法引用错误

我来帮你搞定这个构建报错的问题,看起来是Proguard混淆过程中,Google Play Services的内部类找不到org.json.JSONStringer的相关方法导致的,下面给你几个可行的解决办法:

方法1:添加Proguard规则保留JSONStringer类的方法

直接在你的Proguard配置文件里加上这些规则,确保系统自带的org.json.JSONStringer的方法不会被混淆或移除:

# 保留JSONStringer的所有公共方法,避免Google Play Services内部引用报错
-keep class org.json.JSONStringer {
    public <methods>;
}

# 如果上面的规则还没解决问题,可以加上这条忽略特定类的警告
-dontwarn com.google.android.gms.internal.zzelh

方法2:统一升级Google Play Services和Firebase依赖版本

你现在用的11.8.0版本的Google Play Services和Firebase比较老旧,可能和你用的Android Support库(26.1.0)存在兼容性问题。建议把所有Google相关的依赖统一升级到更稳定的版本(比如12.0.1,注意所有Firebase和Play Services版本必须保持一致),修改后的依赖示例:

// Google Play Services
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
// Firebase模块配置
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-crash:12.0.1'
implementation 'com.google.firebase:firebase-config:12.0.1'
implementation 'com.google.firebase:firebase-invites:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'

方法3:排查重复的JSON库依赖

如果你的项目里除了系统自带的org.json,还引入了第三方JSON库(比如org.json:json),可能会造成类冲突。可以在终端执行./gradlew app:dependencies查看依赖树,找到重复的JSON库后用exclude把它去掉。


你提供的配置信息参考:

原始依赖配置:

dependencies {
    compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') { transitive = true }
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.google.android.gms:play-services-maps:11.8.0'
    implementation 'com.google.android.gms:play-services-location:11.8.0'
    // Firebase模块配置
    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.google.firebase:firebase-crash:11.8.0'
    implementation 'com.google.firebase:firebase-config:11.8.0'
    implementation 'com.google.firebase:firebase-invites:11.8.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    // 其他依赖
    implementation 'com.github.nkzawa:socket.io-client:0.3.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.github.halysongoncalves:pugnotification:1.8.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
}

构建错误日志:

Warning:com.google.android.gms.internal.zzelh: can't find referenced method 'org.json.JSONStringer array()' in program class org.json.JSONStringer
Warning:com.google.android.gms.internal.zzelh: can't find referenced method 'org.json.JSONStringer endArray()' in program class org.json.JSONStringer
Warning:com.google.android.gms.internal.zzelh: can't find referenced method 'org.json.JSONStringer endObject()' in program class org.json.JSONStringer
Warning:com.google.android.gms.internal.zzelh: can't find referenced method 'org.json.JSONStringer key(java.lang.String)' in program class org.json.JSONStringer
Warning:com.google.android.gms.internal.zzelh: can't find referenced method 'org.json.JSONStringer object()' in program class org.json.JSONStringer
Warning:com.google.android.gms.internal.zzelh: can't find referenced method 'org.json.JSONStringer value(java.lang.Object)' in program class org.json.JSONStringer
Warning:there were 6 unresolved references to program class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.

原始Proguard配置:

# Uncomment this to preserve the line number information for debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to hide the original source file name.
#-renamesourcefileattribute SourceFile
-dontwarn com.squareup.okhttp.**
#### -- Picasso --
-dontwarn com.squareup.picasso.**

内容的提问来源于stack exchange,提问作者Yovangga Anandhika Hadi Putra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:42:36