排除lib但在生成项目时出现重复错误

时间:2019-07-03 11:57:31

标签: android-gradle

在我的app / build.gradle中:

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 285
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    configurations {
        all*.exclude group: 'android.support.v4.app', module: 'classes.jar'
        all*.exclude group: 'android.support.v4.accessibilityservice', module: 'classes.jar'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

def AAVersion = '4.6.0'

dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"

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

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.code.gson:gson:2.8.5'

    implementation "org.androidannotations:androidannotations-api:$AAVersion"

    implementation project(':binding')

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

如您所见,我排除了 android.support.v4

在binding / build.gradle中:

def AAVersion = '4.6.0'

dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"

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

    implementation 'commons-io:commons-io:2.6'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'com.google.android.gms:play-services:4.3.23'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'edu.vt.middleware:vt-password:3.1.2'

    implementation "org.androidannotations:androidannotations-api:$AAVersion"

    implementation project(':scanlib')

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

但我收到错误消息:

> Task :app:checkDebugDuplicateClasses FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and support-v4-19.0.1.jar (com.android.support:support-v4:19.0.1)
  Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and support-v4-19.0.1.jar (com.android.support:support-v4:19.0.1)
  Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and support-v4-19.0.1.jar (com.android.support:support-v4:19.0.1)
  Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and support-v4-19.0.1.jar (com.android.support:support-v4:19.0.1)

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码:

 apply plugin: 'com.android.application'

repositories {

maven { url "https://jitpack.io" }
mavenCentral()
}

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "your name app pack"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode *
        versionName "*.*"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    //gson
    implementation 'com.google.code.gson:gson:2.8.5'
}

如果不起作用,请尝试无效并重新启动 android studio