9

update to 'com.android.tools.build:gradle:3.5.0'

find the build error:

Execution failed for task ':truecp_player:mergeDebugJavaResource'. A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade More than one file was found with OS independent path 'classes.jar'

ps: 'com.android.tools.build:gradle:3.4.2' work fine.

update: if the library module with some local .aar file dependency the error will occur!

library module:

apply plugin: 'com.android.library'

def androidConfig = rootProject.extensions.getByName("ext").android

android {
    compileSdkVersion androidConfig.compileSdkVersion
    buildToolsVersion androidConfig.buildToolsVersion

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    api fileTree(include: ['*.jar', "*.aar"], dir: 'libs')

    implementation 'androidx.appcompat:appcompat:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}


庄 鹏
  • 1,024
  • 9
  • 11

3 Answers3

3

I had exactly the same issue and it was caused by .aar and .jar libraries. Looks like you also include some of them in your project:

api fileTree(include: ['*.jar', "*.aar"], dir: 'libs')

In my particular case one of .aar files also contained .jar file with the same name as another .jar file from the /libs folder. Also, I had to change the way of importing .aar files: from /libs folder to independent gradle modules as described in the official docs and here.

fraggjkee
  • 3,524
  • 2
  • 32
  • 38
0

Extracting the jars out of the aars fixes this error.

  • unzip file_name.aar
  • mv classes.jar file_name.jar

Do this for all the aars in the libs folder. Remove everything else from the directory except the jar files.

NSaran
  • 561
  • 3
  • 19
  • How do you call that a solution. The rest of the aar file content is also needed. How could we just remove it? – Żabojad Sep 30 '20 at 10:51
  • I appreciate your concern on the matter. If you can explain the downfalls and implications with my approach that would be very helpful for me as well as OP. – NSaran Oct 02 '20 at 18:33
  • if you want transient dependencies, you're storing your aars on a maven repository (even if it's juts the ~/.m2/repository). this solution is a step in diagnosis, not the solution. – fuzzyTew Feb 27 '21 at 13:14
0

This issue is tracked there: https://github.com/gradle/gradle/issues/10882

For now, it is still not fixed in Gradle.

One possible workaround is to publish the aar to artifactory. See there for information about this.

EDIT: in my case, I could use gradle plugin 3.6.4 instead which solves the problem.

Żabojad
  • 2,946
  • 2
  • 32
  • 39