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

关于AGConnect Crash报ArrayIndexOutOfBoundsException的技术求助

华为AGConnect Crash库ArrayIndexOutOfBoundsException崩溃排查与解决

我的应用在Crashlytics上持续收到崩溃报告,报错为com.huawei.agconnect.crash.internal.log.h$b.read处的ArrayIndexOutOfBoundsException。已尝试搜索相关信息,但未找到有效内容。

最近版本更新了AGConnect相关库后问题仍存在,使用的版本信息如下:

  • 项目级build.gradle:
classpath 'com.huawei.agconnect:agcp:1.7.2.300'
  • 应用级build.gradle:
implementation 'com.huawei.hms:base:6.6.0.300'
implementation 'com.huawei.agconnect:agconnect-core:1.7.2.300'
implementation 'com.huawei.hms:hianalytics:6.7.0.300'
implementation 'com.huawei.agconnect:agconnect-crash:1.7.2.300'
implementation 'com.huawei.hms:push:6.7.0.300'
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.7.2.300'

崩溃仅发生在华为设备上,90%以上为Android 10系统,剩余为Android 11系统。Crashlytics提供的崩溃堆栈如下:

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException:
   at com.huawei.agconnect.crash.internal.log.h$b.read(:51)
   at com.huawei.agconnect.crash.internal.log.e$1.a(:15)
   at com.huawei.agconnect.crash.internal.log.h.a(:21)
   at com.huawei.agconnect.crash.internal.log.e.a(:28)
   at com.huawei.agconnect.crash.internal.log.f.b(:8)
   at com.huawei.agconnect.crash.internal.log.d.a(:215)
   at com.huawei.agconnect.crash.internal.log.c.a(:10)
   at com.huawei.agconnect.crash.internal.log.a$4.run(:6)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
   at java.lang.Thread.run(Thread.java:929)

排查思路与解决方案

1. 统一AGConnect/HMS库版本

当前HMS base库(6.6.0.300)与其他HMS库(hianalytics、push为6.7.0.300)版本不一致,版本不匹配可能引发内部逻辑冲突。建议将所有HMS/AGConnect库升级到同一稳定版本:

  • 项目级agcp插件与AGConnect库版本保持一致,例如:
classpath 'com.huawei.agconnect:agcp:1.8.0.300'
  • 应用级所有HMS/AGConnect库统一对应版本:
implementation 'com.huawei.hms:base:6.8.0.300'
implementation 'com.huawei.agconnect:agconnect-core:1.8.0.300'
implementation 'com.huawei.hms:hianalytics:6.8.0.300'
implementation 'com.huawei.agconnect:agconnect-crash:1.8.0.300'
implementation 'com.huawei.hms:push:6.8.0.300'
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.8.0.300'

2. 清理缓存并重新构建

版本更新后本地缓存可能残留旧文件,导致运行时冲突:

  • 执行./gradlew clean清理项目缓存
  • 重启Android Studio后重新构建项目
  • 卸载设备上的旧应用,重新安装新版本

3. 检查自定义日志上报逻辑

若应用中有自定义调用AGConnect Crash日志上报的代码,排查是否存在传入非法参数(如空数组、长度为0的数组)的情况,避免触发内部解析异常。

4. 临时屏蔽崩溃(应急方案)

若升级版本后问题仍未解决,可通过全局异常捕获临时屏蔽该崩溃,避免影响用户体验:

Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
    if (throwable instanceof ArrayIndexOutOfBoundsException
        && throwable.getStackTrace() != null
        && throwable.getStackTrace().length > 0
        && throwable.getStackTrace()[0].getClassName().contains("com.huawei.agconnect.crash.internal.log")) {
        // 忽略该崩溃,不向上抛出
        return;
    }
    // 其他异常按原有逻辑处理
    // ...
});

5. 提交华为技术支持工单

如果以上方法均无效,收集以下信息提交华为开发者支持工单:

  • 完整的崩溃堆栈信息
  • 应用的AGConnect/HMS配置详情
  • 崩溃设备的型号、系统版本分布数据
  • 可复现崩溃的操作步骤(若存在)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 16:05:31