构建失败:程序类型已存在

时间:2018-04-28 00:15:10

标签: android gradle android-studio-3.0

我在网上搜索过这个错误,这个问题似乎总是出现某种依赖性冲突。我想我应该在某些依赖之后添加exclude,但我不确定哪一个。根据错误我也应该明确排除的依赖性也不清楚;我所知道的是group可能是com.android.support ...

这是我尝试过的:

  1. multiDexEnabled true添加到defaultConfig中的build.gradle块。
  2. 在Android Studio中清理项目。
  3. 手动删除(从文件系统)整个.gradle目录。
  4. 我确保compileSdkVersiontargetSdkVersion相同。
  5. 我已确保所有Android依赖项都使用相同的版本(即26.1.0)。
  6. 尽管如此,我在构建时仍会遇到此错误:

    Program type already present: android.support.compat.R$bool
    

    并从Java编译器:

    Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
    F:\ExampleProject\app\build\intermediates\transforms\dexBuilder\debug\115, 
    F:\ExampleProject\app\build\intermediates\transforms\externalLibsDexMerger\debug\0
    

    这是我的模块的build.gradle文件:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.myapp.exampleproject"
            minSdkVersion 17
            targetSdkVersion 26
            versionCode 1
            versionName "1.2"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support:design:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        implementation 'com.android.support:support-v4:26.1.0'
        implementation 'com.android.support:support-compat:26.1.0'
        implementation 'com.android.volley:volley:1.1.0'
        implementation 'com.github.bumptech.glide:glide:4.1.0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.1.0'
    }
    

    最后,我的项目是build.gradle文件:

    buildscript {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.2'
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    任何帮助纠正这一点将不胜感激。

3 个答案:

答案 0 :(得分:1)

这是Glide 4.1.0的问题。使用版本4.1.1而不是通过从其依赖项中删除R * .class文件来修复错误。 (source

答案 1 :(得分:0)

这可能是因为Glide库。尝试使用以下方法从中排除支持库:

using

您可以在Glide build.gradle

处看到Glide内的支持库

答案 2 :(得分:0)

解决方案:

 implementation ('com.github.bumptech.glide:glide:4.1.0') {
        exclude group: 'com.android.support'
        exclude module: 'support-fragment'
        exclude module: 'appcompat-v7'
    }
相关问题