首页 > 解决方案 > 以 Android Q 为目标时构建失败,但在 API 28 上工作时出现“无法将文件 'android.jar' 转换为匹配属性”

问题描述

我有一个我正在维护的遗留应用程序,它在以 API 28 为目标时构建良好,但在 Q 时失败。

gradle 构建的完整错误如下所示:

> Task :lintVitalRelease
Calling mockable JAR artifact transform to create file: /Users/spartygw/.gradle/caches/transforms-1/files-1.1/android.jar/5fe3ee8a258b0a02d9b262c195a9ab63/android.jar with input /Users/spartygw/Library/Android/sdk/platforms/android-Q/android.jar

> Task :lintVitalRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':lintVitalRelease'.
> Could not resolve all files for configuration ':androidApis'.
   > Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform
      > Cannot create mockable android.jar

我已按照从此处设置 Android Q SDK 的指南进行操作。

我正在从 Android Studio 之外的命令行构建。

我通过构建 jni 库看到了构建进度,但是当它进入 java 字节编译时会立即出错。

编辑:因为我不能包含整个 gradle 堆栈(帖子中限制为 30,000 个字节),所以这里是概要:

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':lintVitalRelease'.
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':androidApis'.
Caused by: org.gradle.api.artifacts.transform.ArtifactTransformException: Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform
Caused by: java.lang.RuntimeException: Cannot create mockable android.jar
Caused by: java.util.zip.ZipException: invalid entry compressed size (expected 1821 but got 1807 bytes)
        at com.android.builder.testing.MockableJarGenerator.createMockableJar(MockableJarGenerator.java:96)
        at com.android.build.gradle.internal.dependency.MockableJarTransform.transform(MockableJarTransform.java:54)
        ... 109 more
        Suppressed: java.util.zip.ZipException: invalid entry compressed size (expected 1821 but got 1807 bytes)

标签: androidbeta-testingandroid-10.0

解决方案


那些通过谷歌搜索并且已经安装了最新的 gradle 的人

只需删除 Android Q SDK 并重新安装。剩下的 beta 安装的 jar 可能会影响最终版本


推荐阅读