什么是 "Program type already present"?

What is "Program type already present"?

当我尝试构建我的 project.i 时遇到此错误

Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat Message{kind=ERROR, text=Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat, sources=[Unknown source file], tool name=Optional.of(D8)}

我也在堆栈溢出中找到解决方案,但它没有help.here是我的build.gradle文件

    apply plugin: 'com.android.application'android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.example.hassan.qrscan"
    minSdkVersion 18
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}}dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'me.dm7.barcodescanner:zxing:1.9'
implementation 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'}
 implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

将依赖版本降级到

 implementation 'com.android.support:appcompat-v7:27.1.0'

并添加设计依赖性

 implementation 'com.android.support:design:27.1.0'

一旦这对我有用就检查它

我使用相同版本的 appcompact 和 design 解决了这个问题

 implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
 implementation 'com.android.support:design:28.0.0-alpha1'

但现在我得到了这个错误

Program type already present: android.support.v4.app.FragmentTransitionCompat21

代替这两个依赖项

implementation 'me.dm7.barcodescanner:zxing:1.9'
implementation 'com.journeyapps:zxing-android-embedded:3.0.2@aar'

添加这两行

implementation('me.dm7.barcodescanner:zxing:1.9'){
   exclude module: 'support-v4'
}

implementation ('com.journeyapps:zxing-android-embedded:3.0.2@aar'){
   exclude module: 'support-v4'
}

希望这会奏效

程序类型已经存在错误只要您的项目有重复的库或具有不同版本的相同库就会出现。 您可以通过 运行

检查依赖关系图
gradlew -q dependencies

gradle -q dependencies

(需要 class 路径中的 Gradle)

把重复的库整理出来,去掉重复的,错误就消失了。