androidbeta-testingandroid-10.0

Build fails when targeting Android Q but works at API 28 with "Failed to transform file 'android.jar' to match attributes"


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)

Solution

  • 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