Development Tip

"이미있는 프로그램 유형"은 무엇을 의미합니까?

yourdevel 2020. 12. 8. 20:07
반응형

"이미있는 프로그램 유형"은 무엇을 의미합니까?


Android Studio에서 앱을 빌드하려고합니다. Eclipse Paho 라이브러리를 gradle 종속성으로 추가 한 후 (또는 Maven입니까? Android 생태계를 처음 사용) 다음 오류가 발생합니다.

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 질문을 확인했지만 답변은 모두 특정 라이브러리에 고유합니다. 나는 오류에 대한 해결책을 찾고있을뿐만 아니라 오류가 의미하는 바를 이해하고 있습니다. 이렇게하면 사람들이 특정 사례에 대한 솔루션을 더 쉽게 파악할 수 있습니다. 지금까지 그에 대한 답변은 없습니다.

다른 StackOverflow 답변에서 내 gradle 파일과 관련이 있다는 것을 수집했습니다. 따라서 여기에 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 라이브러리의 이름 충돌로 인해 발생합니다.

모듈에 대한 종속성 목록app (앱의 기본 모듈 이름) 을 찾으려면 gradlew app:dependencies모든 라이브러리 목록을 검색 할 수 있습니다 .

다음에서 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에서 제공된 버전을 사용합니다.

또한 Eclipse 라이브러리가 다른 버전 (r7 ??)을 사용하고 있음을 알 수 있습니다.

문제를 해결하려면 support-v4다음과 같이이 Eclipse 라이브러리에서 모듈을 제외 할 수 있습니다 .

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

그런 다음 애플리케이션을 컴파일 할 수 있어야합니다.

Btw 코드를 테스트하여 Eclipse 모듈이 손상되지 않도록주의해야합니다.


나를 위해 프로젝트를 청소 하면 문제가 해결되었습니다.

./gradlew clean

From official Doc

If a class appears more than once on the runtime classpath, you get an error similar to the following:

Program type already present com.example.MyClass

This error typically occurs due to one of the following circumstances:

  • A binary dependency includes a library that your app also includes as a direct dependency.

    For example, your app declares a direct dependency on Library A and Library B, but Library A already includes Library B in its binary. To resolve this issue, remove Library B as a direct dependency.

  • Your app has a local binary dependency and a remote binary dependency on the same library.

    To resolve this issue, remove one of the binary dependencies. ( See if same library is added as jar and gradle dependency)


It's happened to me also but in my case, I try to include different dependencies that have same class using debugApi & Api so Android Studio marked as duplicate class, so I solved the issue by using debugApi & releaseApi to include different dependencies based on the build variant.


Add Support library to app level Gradle file

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


In my case it mean I have 2 *.jar file or 2 libary some where in source code. For example: I have 2 youtube.jar in app/libary and module/libary Delete the redundant once and it will be fine

참고URL : https://stackoverflow.com/questions/49676155/what-does-program-type-already-present-mean

반응형