2

I have a gradle android library module that depends on another project android library:

androidlib-a depends on androidlib-b

androidlib-a dependency

implementation project(path: ':androidlib-b', configuration: "default")

Following exception is thrown in configuration phase after upgrading to android build tools 3.5.0 from 3.3.0:

What went wrong: Could not determine the dependencies of task ':androidlib-a:lint'. Could not resolve all artifacts for configuration ':androidlib-a:releaseCompileClasspath'. Failed to transform artifact 'androidlib-b.aar (project :androidlib-b)' to match attributes {artifactType=jar}. Execution failed for IdentityTransform: C:\LocalData\projects\project\androidlib-b\build\outputs\aar\androidlib-b-release.aar. C:\LocalData\projects\project\androidlib-b\build\outputs\aar\androidlib-b-release.aar.

I change the androidlib-a dependency to:

implementation project(':androidlib-b')

The build for androidlib-a from command line works now but I get following issue on an Android Studio Gradle Sync:

ERROR: More than one variant of project :androidlib-b matches the consumer attributes: - Configuration ':androidlib-b:releaseRuntimeElements' variant android-assets: - Unmatched attributes: - Found artifactType 'android-assets' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Compatible attributes: - Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'. - Configuration ':androidlib-b:releaseRuntimeElements' variant android-classes: - Unmatched attributes: - Found artifactType 'android-classes' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Compatible attributes: - Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'. - Configuration ':androidlib-b:releaseRuntimeElements' variant android-consumer-proguard-rules: ...

After the change I have also an issue in another module that depends on androidlib-a and tries to copy the dependencies like that:

task copyToLib() {
    afterEvaluate {
        dependsOn ":androidlib-a:assembleRelease"
    }
    doLast {
        delete libDir
        def config = rootProject.project(":project").configurations.releaseRuntimeClasspath
        println config.toList()
        copy {
            into libDir
            from config
        }
    }
}

preBuild.dependsOn "copyToLib"

Execution failed for task ':anothermodule:copyToLib'. Could not resolve all files for configuration ':androidlib-a:releaseRuntimeClasspath'. More than one variant of project :androidlib-b matches the consumer attributes: - Configuration ':androidlib-b:releaseRuntimeElements' variant android-assets: - Unmatched attributes: - Found artifactType 'android-assets' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Compatible attributes: - Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'. - Configuration ':androidlib-b:releaseRuntimeElements' variant android-classes: - Unmatched attributes: - Found artifactType 'android-classes' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Compatible attributes: - Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.

Same issues are present with android build tools 3.5.1 release.

Full androidlib-a build conifg:

apply plugin: 'com.android.library'

version = releaseVersion

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName releaseVersion
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    implementation project(path: ':androidlib-b', configuration: "default")
}

Full androidlib-b build conifg:

apply plugin: 'com.android.library'

version = releaseVersion

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName releaseVersion
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }
}
Hollerweger
  • 975
  • 1
  • 13
  • 32
  • Could you post the `buildTypes` and `productFlavors` configuration of each lib? – ahasbini Oct 18 '19 at 23:24
  • Also directory structures of the modules (libs + modules depending on libs) with respect to each other would help in figuring out your second issue – ahasbini Oct 18 '19 at 23:29
  • 1
    Cannot see any AAR dependency; those error message do not explain the problem. – Martin Zeitler Oct 23 '19 at 12:31
  • @ahasbini Added Build config for androuidlib-a and b – Hollerweger Oct 23 '19 at 17:06
  • I had similar same issue before when build tools 3.0.x was introduced and then adding the default configuration did the fix. Not sure how this changed again in 3.5.x. Fix related to the 3.0.x build tools issue is described here: https://stackoverflow.com/a/51766919/1100559 – Hollerweger Oct 23 '19 at 17:20

1 Answers1

-1

I can't say if this is your problem but Android Studio 3.5 enables R8 shrinking and minification by default, substituting Proguard -and enabling it I would say even on debug build types at least on some parts-.

There's an issue related to AARs on this version. Android Studio can't find JAR dependencies contained inside AARs. This issue is supposedly to be fixed on Android Studio 3.6.0-alpha05 or higher at Canary channel available for download on Android Studio's website.

Also If AARs doesn't contain any JAR dependency you could still have NoClassDefFoundException or NoSuchMethodError during execution when your AAR library tries to use some third party libraries. This issue doesn't have any fix yet, but you could apply following workaround:

Just add the next line to your gradle.properties at root directory, sync project and rerun:

android.enableD8.desugaring=false

You can also solve both issues by uploading AAR to any respository, like local repository or cloud repositories like JFrog or Nexus private server (if your library is privative) or even to Maven or similar public repository (if your library is public), as these errors just affect to AARs included manually and not to those downloaded from a repository

Rubén Viguera
  • 3,277
  • 1
  • 17
  • 31
  • 1
    I tried with disabling desugaring in 3.5.1 but then I get following log: INFO: The option setting 'android.enableD8.desugaring=false' is experimental and unsupported. The current default is 'true'. -->same issue is occuring. I tried also with 3.6.0-alpha05 but then I get an error from another library that is only compatible with 3.5.x. I will check after removing that one. – Hollerweger Oct 25 '19 at 14:05
  • That log message is only an informative message, not an error. Anyway you can also try to upload you AAR to a local maven repository: https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 – Rubén Viguera Oct 25 '19 at 15:15
  • Isn't `enableD8.desugaring` deprecated now? – IgorGanapolsky Mar 15 '20 at 17:46