以 Android Q 为目标时构建失败,但在 API 28 和 "Failed to transform file 'android.jar' to match attributes" 下工作
Build fails when targeting Android Q but works at API 28 with "Failed to transform file 'android.jar' to match attributes"
我有一个我正在维护的遗留应用程序,它在针对 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
我已按照 here 中的 Android Q SDK 设置指南进行操作。
我正在从 Android Studio 之外的命令行构建。
我通过构建 jni 库看到了构建进度,但是当它到达 java 字节编译时立即 barfs。
编辑:因为我不能包含整个 gradle 堆栈(在 post 中限制为 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)
任何可能通过 google 搜索来到这里的人,我找到了答案。
在 Android Q Beta 2 的发行说明中,我发现 in the release notes 这个简介:
When using Gradle 3.2.0 for projects targeting Android Q, you might encounter a lint-related issue with an error message similar to "Could not transform android.jar to a mockable jar." This issue does not occur in Gradle 3.3.0 and later.
If you are working on an app that targets Android Q and are unable to upgrade to Gradle 3.3.0 or later, you can use one of the following workarounds:
- Disable lint for release builds
- Unzip and rezip android.jar
果然,解压缩和重新压缩 android.jar 允许我构建并部署到我的测试 Android Q 设备
转到工具>SDK 管理器>平台工具和 install/update Android Q 的 SDK 平台工具。您可能需要删除 Android Q 的现有 SDK 平台工具并重新安装
那些正在通过 google 搜索并且已经安装了最新的 gradle 的人
只需删除 Android Q SDK 并重新安装。测试版安装遗留下来的罐子可能会影响最终版本
我有一个我正在维护的遗留应用程序,它在针对 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
我已按照 here 中的 Android Q SDK 设置指南进行操作。
我正在从 Android Studio 之外的命令行构建。
我通过构建 jni 库看到了构建进度,但是当它到达 java 字节编译时立即 barfs。
编辑:因为我不能包含整个 gradle 堆栈(在 post 中限制为 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)
任何可能通过 google 搜索来到这里的人,我找到了答案。
在 Android Q Beta 2 的发行说明中,我发现 in the release notes 这个简介:
When using Gradle 3.2.0 for projects targeting Android Q, you might encounter a lint-related issue with an error message similar to "Could not transform android.jar to a mockable jar." This issue does not occur in Gradle 3.3.0 and later.
If you are working on an app that targets Android Q and are unable to upgrade to Gradle 3.3.0 or later, you can use one of the following workarounds:
- Disable lint for release builds
- Unzip and rezip android.jar
果然,解压缩和重新压缩 android.jar 允许我构建并部署到我的测试 Android Q 设备
转到工具>SDK 管理器>平台工具和 install/update Android Q 的 SDK 平台工具。您可能需要删除 Android Q 的现有 SDK 平台工具并重新安装
那些正在通过 google 搜索并且已经安装了最新的 gradle 的人
只需删除 Android Q SDK 并重新安装。测试版安装遗留下来的罐子可能会影响最终版本