6

I've got a legacy app I'm maintaining that builds fine when targeting API 28 but fails at Q.

The full error from the gradle build looks like this:

> 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

I've followed the guidelines for setting up the Android Q SDK from here.

I'm building from a command line outside of Android Studio.

I see the build progress through building the jni library but barfs immediately when it gets to java byte compilation.

EDIT: Because I can't include the entire gradle stack (limited to 30,000 bytes in a post) here is the synopsis:

* 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)
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
spartygw
  • 3,289
  • 2
  • 27
  • 51

3 Answers3

5

Those of you who are coming through google search and already have the latest gradle installed

Just delete the Android Q SDK and reinstall. The jars from left over beta install is probably messing with the final release

Ganesh Krishnan
  • 7,155
  • 2
  • 44
  • 52
2

Anyone who might be coming here from a google search, I found the answer.

In the release notes for Android Q Beta 2 I found in the release notes this blurb:

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

Sure enough, unzipping and rezipping the android.jar allowed me to build and deploy to my test Android Q device

spartygw
  • 3,289
  • 2
  • 27
  • 51
  • Thank you. You really save my day. By using 7zip I unzip and then zip file "AppData\Local\Android\Sdk\platforms\android-29\android.jar". It mystery for me how it works. – snailp4el Aug 29 '21 at 11:43
2

Go to Tools>SDK manager>platform tools and install/update SDK platform tools for Android Q. You might need to delete the existing sdk platform tools for Android Q and reinstall