Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Asked Answered
S

10

55

I have a project with 2 modules: an app (Java) with build types debug, release, and enterprise and a Kotlin library (release and debug) used by the app.

I'm using AndroidX and have the following in my gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

If I run the project through Gradle, I get a bunch of compile errors (expected). But if I try to use it from within Android Studio (3.2 Beta 5), specifically when trying to sync with the Gradle model, I get this:

Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@release/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@enterprise/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@enterpriseUnitTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform

My settings.gradle:

include ':app',':some-lib'
project(':some-lib').projectDir = file ('../some-lib/lib')

The library module will eventually be its own library used by this app and others, but while I'm working on it I build it as a part of the app. Things were working fine until I switched to AndroidX.

The app module declares the dependency as:

implementation project(path: ':some-lib', configuration: 'default')

If I leave out the configuration: 'default' bit when declaring the dependency, I get:

Unable to resolve dependency for ':app@enterprise/compileClasspath': Could not resolve project :some-lib.
Unable to resolve dependency for ':app@enterpriseUnitTest/compileClasspath': Could not resolve project :some-lib.

Any ideas on what I'm doing wrong here?

Salome answered 11/8, 2018 at 1:37 Comment(1)
I'm getting similar issues to this with 3.2, even without Jetifier/AndroidX :-\ Did using matchingFallbacks work for you? I've been using that since 3.0 and while it still works in 3.1.3, it doesn't seem to work anymore in 3.2.0-rc02Morph
S
14

I could swear I had already tried this, but specifying a set of matchingFallbacks for the build types did the trick:

buildTypes {
    release {
        // blah blah
        matchingFallbacks = ['release']
    }
    enterprise {
        // blah blah
        matchingFallbacks = ['release']
    }
    debug {
        // blah blah
        matchingFallbacks = ['debug']
    }
}

More here

Salome answered 13/8, 2018 at 17:20 Comment(4)
I'm still having the same issue. and I cannot figure out why... it only happens when I use kapt... and if I use implementation project(':library') insteaad of implementation project(path: ':library', configuration:'default') I get another error:Caused by: org.gradle.internal.component.AmbiguousVariantSelectionException: More than one variant of project :library matches the consumer attributes:Counterstroke
The link 'here' is dead.Charie
@Charie Fixed. Thanks.Salome
unfortunately, for me answer below resolves this particular error - but then again, it has its own set of errors with the particular project I'm working on right now!Boughton
P
21

The error seems to be caused by corrupt Jetified files.

Delete ONLY the corrupted .aar from the Gradle caches folder:

rm ~/.gradle/caches/modules-2/files-2.1/path-to/some-release.aar

The "path-to" will be probably be the package name e.g., com.example.somerelease

Sometimes it is possible to get the path of the file to delete from the error message itself and cut and paste it into the terminal in order to execute the rm command.

Deleting the entire folder is not an optimal solution as all the dependencies will need to be Jetified again. If you're already having corruption issues, you're likely to encounter the issue again.

Progress answered 23/5, 2019 at 3:51 Comment(3)
Try not to delete the whole gradle folder if you don't have to. It requires a super-long first build on almost each old project you try to buildKazan
The gradle cache on Windows 10 is in `C:\Users\<username>\.gradle\caches`.Haiku
I faced this problem for another dependency that was part of android framework, and not third party library or module, and resolve it by clear gradle cache. To clear gradle cache manually, only go to path @Haiku mentioned in his/her comment (C:\Users\<username>\.gradle\caches) and then search your dependency name in folders names started with module or transform (e.g. modules-2, transforms-2) and remove all of files and folders related to it. Gradle download them in next build again, even you remove this folders again.Koumis
S
14

I could swear I had already tried this, but specifying a set of matchingFallbacks for the build types did the trick:

buildTypes {
    release {
        // blah blah
        matchingFallbacks = ['release']
    }
    enterprise {
        // blah blah
        matchingFallbacks = ['release']
    }
    debug {
        // blah blah
        matchingFallbacks = ['debug']
    }
}

More here

Salome answered 13/8, 2018 at 17:20 Comment(4)
I'm still having the same issue. and I cannot figure out why... it only happens when I use kapt... and if I use implementation project(':library') insteaad of implementation project(path: ':library', configuration:'default') I get another error:Caused by: org.gradle.internal.component.AmbiguousVariantSelectionException: More than one variant of project :library matches the consumer attributes:Counterstroke
The link 'here' is dead.Charie
@Charie Fixed. Thanks.Salome
unfortunately, for me answer below resolves this particular error - but then again, it has its own set of errors with the particular project I'm working on right now!Boughton
P
4

Try this:

implementation fileTree(include:[':some-lib'], dir: "../lib/path")
Pintsize answered 8/11, 2018 at 23:42 Comment(3)
This solution resolves this particular error, but it has its own set of errors with the particular project I'm working on right now, unfortunately. It fails on linking the resources (cannot find e.g. colours)Boughton
@Boughton Were you able to resolve the colors issue? if yes, how? Thanks.Friend
can't quite remember, sorry... @FriendBoughton
M
4

I got the solution.. Just enter the following lines into build.gradle(app)

compileOptions {
        sourceCompatibility '1.8'
        targetCompatibility '1.8'
    }
Manas answered 1/8, 2019 at 7:25 Comment(0)
R
2

This happens to me when I use jdk11 to build the app.

Switching to jdk8 works for me.

* What went wrong:
Execution failed for task ':****:kaptGenerateStubsDebugKotlin'.
> Could not resolve all files for configuration ':****'.
   > Failed to transform coreService.jar (project :coreService) to match attributes {artifactType=android-classes, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=11, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.localToProject=public, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for JetifyTransform: ****/build/libs/coreService.jar.
         > Failed to transform '****/build/libs/coreService.jar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)
Redraft answered 25/4, 2022 at 4:36 Comment(0)
F
1

Options to resolve this (Priority Wise):

(Note: Follow next only if previous option doesn't work)

  1. update library declaration to following : implementation project(path: ':yourLibraryname', configuration: 'default')
  2. Android Studio > File > Invalidate Caches/Restart.
  3. Goto Users > (Current User) > .gradle > delete caches folder and open Android Studio again.
  4. "assemble" that specific library separately. (Use Gradle option available on RHS of Android Studio.
Fibrinous answered 31/1, 2020 at 22:42 Comment(0)
S
1

What worked was updating my gradle build to the latest version

Swinish answered 5/10, 2021 at 11:39 Comment(0)
S
0

I also encountered such problem today and hopefully I resolved it. The name of .aar file in my case is "open-web-sdk-release.aar".

Error was here, implementation files("libs/open-web-sdk-release") .

I replaced it with, implementation project(":open-web-sdk-release") .

Used this link ... https://developer.android.com/studio/build#module-level .

Sigfried answered 14/8, 2020 at 9:52 Comment(0)
P
0

I resolved the same issue by shortening the path to Gradle User Home:

  1. In terminal: export GRADLE_USER_HOME=/home/.gradle

  2. In android studio: File | Settings | Build, Execution, Deployment | Build Tools | Gradle | Gradle user home: /home/.gradle

  3. Build the project.

Plafker answered 11/9, 2021 at 13:22 Comment(0)
S
0
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  kotlinOptions {
    jvmTarget = '1.8'
  }
Smattering answered 10/1 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.