Gradle plugin 3.5.0: “Failed to transform artifact”, “Execution failed for JetifyTransform”

牧云@^-^@ 提交于 2019-12-25 01:28:24

问题


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.


回答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.



来源:https://stackoverflow.com/questions/57905161/gradle-plugin-3-5-0-failed-to-transform-artifact-execution-failed-for-jetif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!