如何在Android Studio中修复“重复类”

时间:2019-06-08 08:27:08

标签: android gradle duplicates barcode zxing

我正在Android Studio中制作条形码扫描仪应用程序,并使用zxing库。如果我要添加库并要构建项目,则出现问题,“ app:checkDebugDuplicateClasses”步骤将无法正常工作,并且控制台中会出现许多“重复类”错误。

我已经尝试通过“ build.gradle”中的数千个小步骤对其进行修复,但这一切都没有效果。

这是我的 build.gradle 文件:

    compileSdkVersion 28
    defaultConfig {
        applicationId "eu.lenni.kran"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.journeyapps:zxing-android-embedded:3.4.0'
}

多数民众赞成在错误:

org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    ... 6 more
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:23.1.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in

以此类推...

2 个答案:

答案 0 :(得分:0)

尝试将此库添加到build.gradle文件中

implementation 'me.dm7.barcodescanner:zxing:1.9'

implementation 'com.google.android.gms:play-services-vision:17.0.2'

并将此行添加到项目级别的gradle文件中:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url "https://jitpack.io"
        }
    }
}

希望它会有所帮助:)

答案 1 :(得分:0)

使用升级的库版本

implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }

运行完美

有关更多详细信息:-https://github.com/journeyapps/zxing-android-embedded#adding-aar-dependency-with-gradle