Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
976 views
in Technique[技术] by (71.8m points)

java - How to resolve duplicate class error in gradle build?

I have tried to use ibm tone analyzer api for my project, but if I include the dependency I get this error:

Duplicate class javax.annotation.CheckForNull found in modules annotations-3.0.1.jar (com.google.code.findbugs:annotations:3.0.1) and jsr305-3.0.2.jar (com.google.code.findbugs:jsr305:3.0.2) Duplicate class javax.annotation.CheckForSigned found in modules annotations-3.0.1.jar (com.google.code.findbugs:annotations:3.0.1) and jsr305-3.0.2.jar (com.google.code.findbugs:jsr305:3.0.2)

I have tried to delete testing dependencies, but still won't work, please help

App File:

apply plugin: 'com.android.application'

android {
    configurations.all{

            resolutionStrategy.cacheChangingModulesFor 0, 'seconds'

    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.loginapp"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

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

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    compile 'com.ibm.watson:tone-analyzer:7.0.0'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude module: 'jsr305:3.0.2'

    })
    implementation 'com.google.firebase:firebase-auth:16.2.1'

}
// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin

Gradle Build file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()


    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.google.gms:google-services:4.2.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {

    repositories {

        maven {
            url  "https://dl.bintray.com/ibm-cloud-sdks/ibm-cloud-sdk-repo"
        }

        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

add applicationVariants.all to your gradle.build:

android {
    applicationVariants.all { variant ->
        variant.getRuntimeConfiguration().exclude group: 'com.google.code.findbugs', module: 'jsr305'
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...