如何在Android Studio中解决“重复类”问题

3
我正在使用Android Studio开发一款条形码扫描应用程序,并使用zxing库进行开发。但是,当我添加库并构建项目时,'app:checkDebugDuplicateClasses'步骤无法工作,并且控制台中出现许多'duplicate classes'错误。
我已经尝试通过在'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

and so on...


1
这是因为您在“libs”文件夹中添加了某个库两次。 - Yagnesh Lashkari
你能否请把你项目级别和应用程序级别的 build.gradle 文件一起包含在你的问题里吗? - UkFLSUI
2个回答

5

1
尝试在 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"
        }
    }
}

希望能有所帮助 :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接