定位到Android Q时构建失败,但在API 28上无法正常运行,并且显示“无法转换文件'android.jar'来匹配属性”

时间:2019-03-27 18:53:16

标签: android androidq

我正在维护一个旧应用,该应用在定位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堆栈(帖子中限制为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)

3 个答案:

答案 0 :(得分:0)

任何可能通过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设备

答案 1 :(得分:0)

转到工具> SDK管理器>平台工具并安装/更新适用于Android Q的SDK平台工具。您可能需要删除现有的适用于Android Q的sdk平台工具并重新安装

答案 2 :(得分:0)

通过Google搜索访问并已经安装了最新gradle的人

只需删除Android Q SDK并重新安装即可。 Beta版安装后留下的jar可能与最终版本混淆了