“程序类型已经存在"是什么意思?意思? [英] What does "Program type already present" mean?

查看:28
本文介绍了“程序类型已经存在"是什么意思?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android Studio 中构建应用.添加 Eclipse Paho 库作为 gradle 依赖项(或者是 Maven?我是 Android 生态系统的新手)后,出现以下错误:

I'm trying to build an app in Android Studio. After adding the Eclipse Paho library as a gradle dependency(or is it Maven? I'm new to the Android ecosystem), I got the following error:

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)}

我已经检查了许多与此错误相关的不同 StackOverflow 问题,但答案都是特定于某些库的.我不仅要寻找错误的解决方案,还要了解错误意味着什么.这样人们就会更容易找到解决方案他们的具体情况.到目前为止,还没有答案.

I've checked many different StackOverflow questions relating to this error, but the answers are all specific to certain libraries. I'm looking not only for a solution to the error, but an understanding of what the error means. That way it'll be easier for people to figure out solutions for their specific cases. So far, no answer has provided that.

从其他 StackOverflow 答案中,我发现它与我的 gradle 文件有关.所以,这是 app/build.gradle:

From other StackOverflow answers, I've gathered that it has something to do with my gradle file. So, here's app/build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "---REDACTED FOR PRIVACY---"
        minSdkVersion 15
        targetSdkVersion 27
        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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:support-media-compat:27.1.0'
    implementation 'com.android.support:support-v13:27.1.0'
    implementation 'com.google.android.gms:play-services-maps:12.0.1'
    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.constraint:constraint-layout:1.0.2'
    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'
}

repositories {
    maven { url 'https://repo.eclipse.org/content/repositories/paho-releases/' }
} 

推荐答案

这个问题通常来自命名冲突,在你的例子中是 support-v4 库,它被多个库使用.

This problem usually come from a naming conflict, in your case the support-v4 library, which is use by several libraries.

要查找模块app(应用的默认模块名称)的依赖项列表,我们可以执行一个gradlew app:dependencies检索所有库的列表.

To find the list of dependencies for the module app (default module's name for the app) we can do a gradlew app:dependencies to retrieve a list of all the libraries.

我们发现support-v4被用于:

//short version of the dependencies list highlighting support-v4
+--- com.android.support:support-v13:27.1.0
|    \--- com.android.support:support-v4:27.1.0

+--- com.google.android.gms:play-services-maps:12.0.1
|    +--- com.google.android.gms:play-services-base:12.0.1
|    |    +--- com.google.android.gms:play-services-basement:12.0.1
|    |    |    +--- com.android.support:support-v4:26.1.0 -> 27.1.0 (*)

+--- org.eclipse.paho:org.eclipse.paho.android.service:1.0.2
|    +--- com.google.android:support-v4:r7  // <- problem here

我们看到地图上的 support-v4 将使用 support-v13 提供的版本.

We see that the support-v4 on Maps will use the version provided from support-v13.

我们还看到 eclipse 库正在使用另一个版本(r7 ??).

We also see that the eclipse library is using another version (r7 ??).

要解决您的问题,您可以尝试从这个 eclipse 库中排除模块 support-v4,如下所示:

To resolve your issue, you can try to exclude the module support-v4 from this eclipse library like this:

implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
    exclude module: 'support-v4'
}

然后您应该能够编译您的应用程序.

Then you should be able to compile your application.

顺便说一句,您应该注意 eclipse 模块不会因测试您的代码而中断.

Btw you should take care that the eclipse module won't break by testing your code.

这篇关于“程序类型已经存在"是什么意思?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆