首页 > 解决方案 > 预期为 BEGIN_ARRAY,但在生成 APK 时为第 1 行第 2 列路径 $ 的 BEGIN_OBJECT

问题描述

我的项目在 AVD 上正确运行。但是当我尝试生成签名的 APK 时,gradle 得到这个错误:

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
> Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more 
log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

我已经多次使用此命令:gson.fromJson. 但我找不到错误来源。(哪个文件和哪一行)。

那么如何找到错误的根源

标签: gradlegson

解决方案


当我进行 Gradle 同步时,我在 Android Studio 4.0 中遇到了这个问题。我通过执行以下操作来修复它:

  1. 打开顶层build.gradle并将 gradle 类路径更改为:

    classpath 'com.android.tools.build:gradle:4.0.0'
    
  2. 打开gradle\wrapper\gradle-wrapper.properties并将分发 URL 更改为:

    distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
    
  3. .idea\jarRepositories.xml从新项目中复制

不知道如何或为什么,但它对我有用


推荐阅读