如何解决gradle构建中的重复类错误? [英] How to resolve duplicate class error in gradle build?

查看:532
本文介绍了如何解决gradle构建中的重复类错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为项目使用ibm音频分析器api,但是如果包含依赖项,则会出现此错误:

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

在模块中找到重复的类javax.annotation.CheckForNull注解3.0.1.jar(com.google.code.findbugs:annotations:3.0.1)和jsr305-3.0.2.jar(com.google.code.findbugs:jsr305:3.0.2)复制在模块中找到的类javax.annotation.CheckForSigned注解3.0.1.jar(com.google.code.findbugs:annotations:3.0.1)和jsr305-3.0.2.jar(com.google.code.findbugs:jsr305:3.0.2)

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

应用文件:

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文件:

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
}

推荐答案

将applicationVariants.all添加到gradle.build中:

add applicationVariants.all to your gradle.build:

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

这篇关于如何解决gradle构建中的重复类错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆