Android 生成失败:程序类型已存在
我在网上搜索过这个错误,问题似乎总是以某种依赖冲突而告终。我想我应该在某些依赖项之后添加Android 生成失败:程序类型已存在,android,gradle,android-studio-3.0,Android,Gradle,Android Studio 3.0,我在网上搜索过这个错误,问题似乎总是以某种依赖冲突而告终。我想我应该在某些依赖项之后添加排除,但我不确定是哪一个。基于我应该排除的依赖性的错误,这也不清楚;我只知道组可能是com.android.support 以下是我尝试过的: 将multiDexEnabled true添加到build.gradle中的mydefaultConfig块中 在Android Studio中清理项目 手动(从文件系统)删除整个.gradle目录 我已确保compileSdkVersion和targetSdkVer
排除,但我不确定是哪一个。基于我应该排除的依赖性的错误,这也不清楚;我只知道组
可能是com.android.support
以下是我尝试过的:
将multiDexEnabled true
添加到build.gradle
中的mydefaultConfig
块中
在Android Studio中清理项目
手动(从文件系统)删除整个.gradle
目录
我已确保compileSdkVersion
和targetSdkVersion
是相同的
我已经确保我所有的Android依赖项都使用相同的版本(即26.1.0
)
尽管如此,我在构建时仍然会遇到以下错误:
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'
}
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
}
最后,我的项目的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'
}
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
}
如果您能帮助纠正此问题,我们将不胜感激。这可能是因为Glide库。尝试使用以下方法将支持库从中排除:
// add support-fragment removed from Glide.
implementation "com.android.support:support-fragment:26.1.0"
implementation ('com.github.bumptech.glide:glide:4.1.0') {
exclude group: 'com.android.support'
exclude module: 'support-fragment'
exclude module: 'appcompat-v7'
}
您可以在Glide中的中看到支持库。这是Glide 4.1.0的一个问题。改用版本4.1.1,该版本通过从依赖项中删除R*.class文件来修复该错误。()解决方案:
implementation ('com.github.bumptech.glide:glide:4.1.0') {
exclude group: 'com.android.support'
exclude module: 'support-fragment'
exclude module: 'appcompat-v7'
}
不幸的是,我仍然得到同样的错误(我能够成功地构建它,您使用的是哪个android studio版本?android studio 3.1.2。错误保持不变。在尝试重建之前,除了清理和删除.gradle目录之外,我还应该做些什么吗?我怀疑它仍然会产生错误,因为构建文件挂在某处…而不是ks的信息+源。我很遗憾地报告,在删除该行后仍然出现错误(除了添加另一个答案中建议的Glide排除)。@user9712684我在Glide中发现了问题。哇,这真是一个鬼鬼祟祟的错误!非常感谢,已经修复了问题!:)