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 ofcom.android.application
) - I tried updating appcompat dependency to
androidx.appcompat:appcompat:1.1.0
in affected modules and also removing that dependency
- I checked that the problematic modules use
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.
android.useAndroidX=true
&android.enableJetifier=true
in gradle.properties file? – Whiff