programing

덱스를 병합할 수 없습니다.

elecom 2023. 8. 1. 20:18
반응형

덱스를 병합할 수 없습니다.

Android Studio 베타 버전이 있습니다.이전 모듈을 컴파일하여 새 프로젝트를 만들었지만 앱을 실행하려고 할 때 다음과 같은 메시지와 함께 실행되지 않았습니다.

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

전령의건축업자, 건축업자덱스 아카이브 병합예외:덱스를 병합할 수 없습니다.

하지만 저는 이 오류를 어떻게 해결해야 할지 모르겠습니다.저는 이것을 몇 시간 동안 검색했지만 성공하지 못했습니다.

내 프로젝트는 훌륭합니다.

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta6'
        classpath "io.realm:realm-gradle-plugin:3.7.1"
        classpath 'com.google.gms:google-services:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

내 앱 그라들:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "parad0x.sk.onlyforyou"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    compileOptions {
        targetCompatibility 1.7
        sourceCompatibility 1.7
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    lintOptions {
        checkReleaseBuilds false
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile project(path: ':loginregisterview')


}

그리고 내 모듈 그라들:

    apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    testCompile 'junit:junit:4.12'
    compile project(path: ':parser')

}

두 번째 모듈:

     apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    realm {
        syncEnabled = true
    }
    useLibrary 'org.apache.http.legacy'

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'junit:junit:4.12'
    //  compile 'com.android.support:appcompat-v7:23.1.0'

    //   compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
    compile 'com.google.code.gson:gson:2.6.2'
}

____________________________________________.

두 번째 모듈(파서)을 가져오지 않았을 때는 앱이 인덱스에서 충돌하지 않았지만 모듈을 가져오지 않았을 때는 앱이 작동하지 않았습니다. :D :D

저는 위의 모든 것을 시도했지만 아무도 도움이 되지 않습니다.마침내, 저는 이 일을 찾아냈습니다.

app/build.gradle:

android {
    defaultConfig {
       multiDexEnabled true
    }
}

업데이트할 때도 같은 문제가 있었습니다.com.google.android.gms:play-services:11.2.2com.google.android.gms:play-services:11.4.0이것으로 해결되었습니다.

  1. 깨끗한
  2. 재구축

경고에 주의하세요!

때로는 경고만 제거하면 오류가 자동으로 사라집니다.아래의 특수한 경우를 참조하십시오.


에서 이 두 가지 종속성을 가지고 있었습니다.build.gradle파일 이름:

implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'

그리고 Studio는 (덱스 병합 문제 에도) 다음과 같이 경고했습니다.

든모.com.android.support라이브러리는 정확히 동일한 버전 사양을 사용해야 합니다(슬립된 버전은 런타임 충돌로 이어질 수 있습니다). 발된전을 .27.0.2,21.0.3예를 들어 다음과 같습니다.com.android.support:animated-vector-drawable:27.0.2그리고.com.android.support:support-v4:21.0.3

그래서 저는 의 버전(자세한 내용은 여기 참조)과 두 가지 문제(경고 및 덱스 병합과 관련된 문제)가 모두 해결되었다고 명시적으로 판단했습니다.

implementation 'com.android.support:support-v4:27.0.2'  // Added this line (according to above warning message)
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'

다른 유사한 상황에 대해서는 아래 설명을 참조하십시오.

저의 경우, 불행하게도, 미셸의 해결책이나 수라크의 해결책은 저에게 효과가 없었습니다.

그래서 저는 다음과 같은 방법으로 이 문제를 해결했습니다.

Gradle:3.0에서는 컴파일 구성이 더 이상 사용되지 않으므로 구현 또는 api로 대체해야 합니다.자세한 내용은 여기에서 읽을있습니다. Gradle Build Tool에서 공식 문서를 읽을 수 있습니다.

컴파일 구성은 여전히 존재하지만 API 및 구현 구성이 제공하는 보장을 제공하지 않으므로 사용해서는 안 됩니다.

컴파일보다는 구현이나 api를 사용하는 것이 좋습니다.

컴파일을 구현으로 대체하고, debugCompile withdebugImplementation, testCompile with testAndroidTestImplement

예:이것 대신에

compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'

이런 식으로 쓰시오

implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'

그 후에

  • 프로젝트 내부의 .gradle 폴더를 삭제합니다(.gradle을 보려면 왼쪽 상단의 탐색기에서 "프로젝트" 보기로 전환해야 합니다).
  • 모든 빌드 폴더와 그래들 캐시를 삭제합니다.
  • 빌드 메뉴에서 프로젝트 정리 버튼을 누릅니다.
  • 작업이 완료되면 빌드 메뉴에서 프로젝트 재구성 버튼을 누릅니다.

도움이 되기를 바랍니다!

  1. 를 합니다..gradle디렉토리입니다.

  2. 앱을 다시 실행합니다.

메모들

  • .gradle디렉터리가 프로젝트의 루트 폴더에 있습니다. (숨겨진 파일을 먼저 표시해야 할 수도 있습니다.)
  • Android 3.0을 사용하여 종속성 모듈을 업데이트할 때마다 이 작업을 수행해야 합니다. (Android Studio 3의 최신 버전이 문제를 해결한 것 같습니다.)

입니다..gradleSuragch가 제안한 것처럼 저에게는 충분하지 않았습니다.추가적으로, 저는 그것을 수행해야 했습니다.Build > Clean Project.

보려면 위해보가 있습니다..gradle왼쪽 상단의 네비게이터에서 "프로젝트" 보기로 전환해야 합니다.

Switch to project view

저는 다른 모든 해결책을 시도했지만 아무도 저를 위해 일하지 않았습니다.마지막에는 동일한 종속 버전을 사용하여 편집하여 해결했습니다.build.gradle다른 종속 버전의 지원 또는 구글 라이브러리를 사용하는 Gradle에 라이브러리를 추가할 때 이 문제가 발생한다고 생각합니다.

빌드 그래들 파일에 다음 코드를 추가합니다.그리고나서clean그리고.rebuild프로젝트.

ps: 그것은 나에게 오래된 솔루션이었기 때문에 당신은 다음 라이브러리의 업데이트된 버전을 사용해야 합니다.

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion '26.1.0'
        }
    } else if (requested.group == "com.google.android.gms") {
        details.useVersion '11.8.0'
        } else if (requested.group == "com.google.firebase") {
            details.useVersion '11.8.0'
          }
      }
}

if(1. 청소 및 재구축 노력) 그렇다면 좋습니다.

그렇지 않으면 (2).그라들 작업을 제거하려고 노력합니다) 그러면 좋습니다.

그렇지 않으면 -> 3.grade.properties를 추가합니다.

android.enableD8 = false

2021년 편집:이 세 번째 옵션은 이제 더 이상 사용되지 않습니다. 다른 옵션을 사용하십시오.

추가 -> 4. 가추multiDexEnabled체격에 한.gradle ▁true에▁to.

android {
    compileSdkVersion 26
    defaultConfig {
      ...
        minSdkVersion 15
        targetSdkVersion 26
        multiDexEnabled true
     ...
    }
}

그리고 종속성을 추가합니다.

dependencies {
    compile 'com.android.support:multidex:1.0.1'}

첫 번째 것이 당신 등에게 효과가 있을 수도 있지만, 예를 들어, 그것은 당신의 문제의 성격에 달려 있습니다.

이 라이브러리를 추가하면 오류가 발생합니다.

implementation 'com.jjoe64:graphview:4.2.2'

나중에 이를 확인하고 동일한 버전의 지원 라이브러리를 추가해야 한다는 사실을 알게 되었습니다.그래서 저는 다른 버전을 시도해야 합니다.

compile 'com.jjoe64:graphview:4.2.1'

그리고 그것은 문제를 해결합니다.그러니 그것에 주목하세요.

제 경우 문제는 룸 라이브러리 때문이었습니다.

compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'

다음으로 변경:

compile 'android.arch.persistence.room:runtime:1.0.0'

일했다.

위의 솔루션에 추가하려면 다음과 같이 하십시오.

여러 위치 또는 동일한 파일에서 서로 다른 버전의 종속성을 가리키는 중복 종속성이 없는지 확인합니다.

안녕하세요. 저는 거의 모든 것을 시도해 본 것과 같은 문제가 있습니다.그래서 6시간 동안 고생한 끝에 한 줄 한 줄 디버깅으로 해결했습니다.

classpath 'com.google.gms:google-services:3.0.0'

Google 서비스 3.0 playServiceVersion 11.6.0 이하의 Studio 3.0에서는 파이어베이스를 지원하지 않습니다.

implementation "com.google.firebase:firebase-messaging:$rootProject.ext.playServiceVersion"
implementation "com.google.firebase:firebase-core:$rootProject.ext.playServiceVersion"
implementation "com.firebase:firebase-jobdispatcher-with-gcm-dep:$rootProject.ext.jobdispatcherVersion"

솔루션:

Google 서비스를 다음으로 변경했습니다.

classpath 'com.google.gms:google-services:3.1.1'

그리고 그것은 소방 기지 서비스를 지원합니다.

누군가가 시간을 절약하기를 바랍니다.

  1. 가능하게 하다

    기본 구성 {multiDexEnabled true}

  2. 1단계가 작동하지 않는 경우

    프로젝트 구조로 이동하여 다른 버전을 사용하는 외부 라이브러리를 확인하십시오.두 번 클릭하고 jar 파일을 삭제합니다.프로젝트를 닫고 다시 열면 Android 스튜디오가 프로젝트를 다시 빌드합니다.그 문제는 사라져야 합니다.

가능성 중 하나는 종속성에 버전이 다른 동일한 라이브러리가 존재하는 것입니다.

gradle 파일의 다음 행에 문제가 있었습니다.

  • compile fileTree(include: ['*.jar'], dir: 'libs')
  • compile 'com.google.code.gson:gson:2.8.2'

gson 라이브러리는 내 libs 디렉토리에 있었지만 이전 버전입니다.는 삭습니다했을 했습니다.gson-2.3.1.jar이 normallibs로 돌아갑니다.

지원을 포함한 후 이.build.gradle대상:

implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
    exclude group: 'org.jetbrains', module: 'annotations'
}

이것은 Android Studio 3.0 베타 6에서 작동합니다.자세한 내용은 이 답변을 참조하십시오.

Android Studio 3.0의 안정적인 빌드를 사용하면 아래 단계에서 작업할 수 있습니다.

  1. SdkManager--> Android Sdk --> Sdk Tools 및 Google Play 서비스를 최신 버전 46으로 업데이트합니다.
  2. 프로젝트를 정리하고 프로젝트를 다시 빌드합니다.

[ DEX를 병합할 수 없음 해결됨] 스택 오버플로가 몇 시간 동안 지속된 후 "DEX 병합할 수 없음 오류"를 해결했습니다.

  1. 모든 com.android를 업데이트합니다.v27.1.0에 대한 Gradle의 지원 라인

원인 - Android가 지원 라이브러리를 v27.1.0으로 업데이트했으므로 Gradle 파일의 모든 Android 지원 라인을 26.1.0에서 27.1.0으로 변경해야 합니다.

  1. 리포지토리 섹션에 "https://maven.google.com " 끝점이 있는 메이븐 섹션이 포함되어 있는지 확인합니다.예:

    모든 프로젝트 {리포지토리 {jcentersmaven {url "https://maven.google.com "}} }

원인 :- Android는 SDK 관리자에서 지원 라이브러리를 업데이트할 수 없으며 이제 maven.google.com 를 사용하여 업데이트하므로 27.1.0 지원 라이브러리를 사용하려면 이 라이브러리를 포함해야 합니다.

버전 변경 후: 1.프로젝트 정리 2.프로젝트 재구성

아래에 명령 추가:

android {
...

    dexOptions {

        jumboMode true
        javaMaxHeapSize "4g"

    }
}

Google Play 서비스(최신 버전) 설치 + 다음을 포함합니다.

android {
    defaultConfig {
        multiDexEnabled true
        }
}

build.gradle에서 문제를 해결했습니다. 프로젝트를 청소하고 다시 빌드하십시오!

저의 경우 프로젝트의 libs 폴더에 추가한 것은 gson-2.8.1.jar였습니다.하지만 SDK를 통해 이미 참조가 있었습니다.따라서 libs 폴더에 gson-2.8.1.jar를 추가할 필요가 없었습니다.

제가 그것을 꺼냈을 때, gson-2.8.1.jar 프로젝트는 이 이상한 오류 없이 컴파일됩니다.

그러니 libs 폴더와 종속성을 수정해 보세요.

저는 Chris-Jr의 의견에 동의합니다.Firebase를 사용하여 AdMob 광고를 포함하는 경우(또는 포함하지 않더라도) 플레이 서비스 분석에는 의존성으로 추가하지 않더라도 플레이 서비스 광고가 포함됩니다.분석 결과 11.4.0이 아닌 10.0.1 버전의 광고가 포함되어 있기 때문에 Google은 분명히 11.4.0 롤아웃에서 실수를 했습니다(그림의 마우스 힌트는 이를 보여줍니다).

맨 위에 'com.google.gms:play-services-ads:11.4.0' 컴파일을 수동으로 추가했는데, 이는 인스턴트 실행을 비활성화한 후에만 가능합니다. http://stackoverflow.com/a/35169716/530047

따라서 10.0.1로 되돌아가거나 광고를 추가하고 인스턴트 실행을 비활성화합니다.그게 도움이 된다면 제가 찾은 것입니다.

저는 같은 문제에 부딪혔고 제 경우의 진짜 이유를 찾았습니다.이전에 저도 이전의 답변을 모두 다시 시도했지만 문제가 해결되지 않았습니다.제 웨어 앱 프로젝트에는 다음과 같은 build.gradle 모듈이 두 개 있습니다.

마모 모듈의 build.gradle:

implementation project(':common')
implementation files('libs/farmer-motion-1.0.jar')

공통 모듈의 build.gradle:

implementation files('libs/farmer-motion-1.0.jar')

Gradle 3.x로 업그레이드하기 전에 '구현'은 모두 '컴파일'입니다.

스택 추적 옵션을 사용하여 gradlew를 실행하여 스택 추적을 가져오는데, 이 문제가 발생하면 gradle 콘솔 창에서 이 옵션을 클릭하면 됩니다.그리고 병 패키지에 대한 의존성이 반복된다는 것을 발견했습니다.

Caused by: com.android.dex.DexException: Multiple dex files define Lcom/farmer/motion/common/data/pojo/SportSummary$2;

Farmer-motion-1.0.jar 패키지의 클래스 스포츠 요약은 공식 마이그레이션 가이드를 읽은 후 build.gradle을 다음과 같이 변경했습니다.

마모 모듈의 build.gradle:

implementation project(':common')
// delete dependency implementation files('libs/farmer-motion-1.0.jar')

공통 모듈("build.gradle"):

api files('libs/farmer-motion-1.0.jar') // change implementation to api

이제 마모 모듈은 공통 모듈에 의한 farmer-motion-1.0.jar 내보내기에 종속됩니다.런타임 중 jar 패키지에 대한 종속성이 없는 경우 jar 패키지의 '구현' 종속성도 'compile'변경할 수 있습니다.오직 '뿐.

저도 문제가 있었습니다.

나는 변화를 통해 해결할 수 있었습니다.compileSdkVersion그리고.targetSdkVersion최신 버전으로.

우리 프로젝트를 위해 실수로 같은 병을 다른 이름으로 두 번 추가했습니다.그 중 하나를 제거하면 문제가 해결되었습니다.

문제가 아닐 수도 있지만 프로젝트의 종속성 {} 섹션에 동일한(그러나 이름이 다른) 라이브러리 두 개를 실수로 포함시켰을 때 이 오류가 발생했습니다.

저는 app\build.gradle의 Firebase 메시지를 업데이트하고 있었습니다.

compile 'com.google.firebase:firebase-messaging:10.0.1'

로.

compile 'com.google.firebase:firebase-messaging:11.4.2'

가능한 근본 원인 중 하나: Android Studio에서 다중 모듈 프로젝트를 가져오는 동안 제대로 처리되지 않은 일시적인 종속성이 중복되는 것입니다.목록을 확인하고 제거합니다.저에게 해결책은 말 그대로 다음과 같습니다.

--- a/project/module/build.gradle
+++ b/project/module/build.gradle
@@ -21,5 +21,4 @@ android {
 dependencies {
     implementation project(':upstream-dependency-project')
     implementation 'com.android.support:support-v4:18.0.0'
-    implementation files('libs/slf4j-android-1.6.1-RC1.jar')
 }

저는 제 프로젝트를 위해 이 문제의 원인을 알아봅니다.build.gradle에서 종속성이 두 번 추가되었습니다.한 번은 종속성을 추가하고 한 번은 병 종속성을 추가합니다.

'compile 엔진:차트 compile.chart 엔진:차트 엔진:1.2.0'
...
파일 engine-1을(를) 참조하십시오. /chart engine-1.2.0.jar')

해결된 첫 번째 라인 문제를 제거한 후.

주요 답변이 효과가 없는 경우 동일한 라이브러리에 종속된 여러 종속성이 문제일 수 있습니다.

다음은 몇 가지 디버깅 팁입니다.코드에서, 이샘코드서에플,서,com.google.code.findbugs:jsr305:3.0.0문제가 되는 라이브러리입니다.

솔루션을 확인하기 위해 수정할 때마다 항상 청소 및 재구축하십시오!

  1. --stacktrace자세한 내용을 보려면 플래그를 누르십시오.그것은 도서관을 찾기 위해 구글이라는 수업에 대해 불평할 것입니다.다음은 Android 스튜디오가 항상 플래그와 함께 Gradle을 실행하도록 설정하는 방법입니다.

  2. Studio Android 콘솔 View > Tool Windows > Gradle Console

  3. 을 실행하여 합니다../gradlew -q app:dependenciesbuild.gradle을 수정할 때마다 이를 다시 실행할 수 있습니다.

  4. 빌드.그래들,

    android {
            ...
            configurations.all {
                resolutionStrategy {
                    // Force a particular version of the library 
                    // across all dependencies that have that dependency
                    force 'com.google.code.findbugs:jsr305:3.0.0'
                }
            }
    }
    
  5. 빌드.그래들,

    dependencies {
        ...
        implementation('com.google.auth:google-auth-library-oauth2-http:0.6.0') {
            // Exclude the library for this particular import
            exclude group: 'com.google.code.findbugs'
        }
    }
    
  6. 빌드.그래들,

    android {
        ...
        configurations.all {
            resolutionStrategy {
                // Completely exclude the library. Works for transitive
                // dependencies.
                exclude group: 'com.google.code.findbugs'
            }
        }
    }
    
  7. 종속성 중 일부가 jar 파일에 있는 경우 jar 파일을 열고 충돌하는 클래스 이름이 있는지 확인합니다.만약 그렇다면, 여러분은 아마도 새로운 클래스 이름으로 항아리를 다시 만들거나 음영을 조사해야 할 것입니다.

추가 배경 정보:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

라이브러리에서 이 문제가 발생한 경우 라이브러리가 프로젝트에 성공적으로 추가되었지만 앱을 실행하면 이 오류가 표시됩니다.따라서 이러한 문제가 발생할 경우 Github으로 이동하여 문제를 확인하거나 새로운 문제를 제기할 수 있습니다.도서관에 대한 해결책을 찾지 못하면 교체하는 것이 좋습니다.

언급URL : https://stackoverflow.com/questions/46267621/unable-to-merge-dex

반응형