Gradle plugin 3.5.0: "Failed to transform artifact", "Execution failed for JetifyTransform"
Asked Answered
R

1

2

We updated Android Gradle plugin from 3.4.2 to 3.5.0 (and Gradle from 5.1.1 to 5.4.1).

After that, the build started failing in a few submodules. Trying to assemble any build variant yields this (same error on the command line and in Android Studio):

> Failed to transform artifact 'bottom-navigation.aar (project :bottom-navigation)' to match attributes {artifactType=jar}.
   > Execution failed for JetifyTransform: <project_root>/bottom-navigation/build/outputs/aar/bottom-navigation-release.aar.
      > Failed to transform '<project_root>/bottom-navigation/build/outputs/aar/bottom-navigation-release.aar' using Jetifier. 
        Reason: Cannot open a library at 'FileMapping(from=<project_root>/bottom-navigation/build/outputs/aar/bottom-navigation-release.aar, to=<project_root>/bottom-navigation/build/.transforms/9b2af95a5f0e0055110660c22ff05ab5/jetified-bottom-navigation-release.aar)'. (Run with --stacktrace for more details.)

Any ideas how to fix this?

What I've tried

  • "Invalidate caches" in AS and also clearing all Gradle caches in ~/.gradle/caches as suggested in this answer
  • All the advice in this somewhat similar question
    • I checked that the problematic modules use apply plugin: 'com.android.library' (instead of com.android.application)
    • I tried updating appcompat dependency to androidx.appcompat:appcompat:1.1.0 in affected modules and also removing that dependency

Update

It starts to look like something is wrong in Gradle plugin 3.5.0; builds behave erratically for me locally and on our CI machine.

For example, clean builds are failing: ./gradlew clean assembleBetaRelease fails while ./gradlew assembleBetaRelease works!

Also, sometimes I get AAPT: error: attribute ... not found instead of the above Failed to transform artifact error.

Reverting to Gradle plugin 3.4.2, all these problems disappear.

Edit Oct 2019: Still seeing this weird behaviour with Gradle plugin 3.5.1. Edit Nov 2019 And 3.5.2. Upgrading to Gradle 5.6 didn't help either.

Redfin answered 12/9, 2019 at 10:53 Comment(5)
Did you missed android.useAndroidX=true & android.enableJetifier=true in gradle.properties file?Whiff
are using a React Native project?Vert
@JeelVankhede: we have both of those in project-wide gradle.properties.Redfin
@sajadabbasi: no, this project has nothing to do with React Native.Redfin
@Redfin Please verify that you're not having any support library artifact in any module.Whiff
R
-1

A bit weird, but I got it working again. Apparently just a temporary glitch in Android Gradle plugin related to caching.

This answer helped me:

The simple way to solve this is to switch between your build variants. This refreshes the cached copies and resolves the issue.

I couldn't do that in Android Studio since the project sync was failing, but on the command line I tried another variant (in my case ./gradlew assembleBetaDebug having used ./gradlew assembleBetaRelease earlier). The build passed, and after that it worked for all all other variants too, and Gradle sync in Android Studio started working as well!

Edit: actually this is not completely solved; see updated question.

Update 12/2019: bundle* commands work fine, it's only assemble* that fails—still failing with Android Gradle plugin 3.5.3. Building in Android Studio works fine. Obviously this is not a common issue, and I don't know what exactly in the particular project I'm working on is causing this.

Update 04/2020: now with Android Gradle plugin 3.6.2 (and Gradle 5.6.4) builds work for me locally and I was able to update the project. On CircleCI, the build still occasionally fails with "Failed to transform artifact" but re-running fixes it. Go figure 🤔

Redfin answered 12/9, 2019 at 11:16 Comment(2)
Actually this problem is nastier than that — now I'm getting it again for example when I run ./gradlew clean assembleBetaRelease, while ./gradlew assembleBetaRelease works! And we ran into the same issue in our CI environment; haven't been able to fix that yet. I'm considering reverting back to 3.4.2 to make builds reliable again.Redfin
I also had this issue using Android Gradle plugin 3.5.3 with Gradle 5.4.1. I reverted the Android Gradle plugin to 3.4.2 and it works.Soapsuds

© 2022 - 2024 — McMap. All rights reserved.