programing tip

작업에 대한 Android Studio 3.0 실행 실패 : dex를 병합 할 수 없음

itbloger 2020. 11. 13. 07:54
반응형

작업에 대한 Android Studio 3.0 실행 실패 : dex를 병합 할 수 없음


다음과 같이 빌드 실행 중에 android studio에서 빌드 오류가 발생했습니다.

오류 : ': app : transformDexArchiveWithExternalLibsDexMergerForDebug'작업에 대한 실행이 실패했습니다. java.lang.RuntimeException : java.lang.RuntimeException : com.android.builder.dexing.DexArchiveMergerException : dex를 병합 할 수 없음 "

내 app : build.gradle 파일 :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.pdroid.foodieschoice"
        minSdkVersion 16
        targetSdkVersion 25
        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.constraint:constraint-layout:1.0.2'
    compile 'com.firebaseui:firebase-ui-auth:2.3.0'

    testCompile 'junit:junit:4.12'
}
configurations.all {
    resolutionStrategy {
        force 'com.android.support:appcompat-v7:26.0.1'
        force 'com.android.support:support-compat:26.0.1'
        force 'com.android.support:support-core-ui:26.0.1'
        force 'com.android.support:support-annotations:26.0.1'
        force 'com.android.support:recyclerview-v7:26.0.1'
    }
}

apply plugin: 'com.google.gms.google-services'

모든 솔루션

편집 : 나는 firebase github 사이트를 통해 샘플을 처리하고 해결했습니다.


Cordova 기반 프로젝트의 경우 @mkimmet이 제안한 cordova clean android대로 빌드 전에 다시 실행 하십시오 .


이 오류는와 호환되지 않을 수있는 외부 라이브러리를 추가 할 때 발생합니다 compileSdkVersion.

당신이를 추가 할 때주의해야합니다 external library.

이 문제에 이틀을 보냈고 마침내 다음 단계에 따라 해결되었습니다.

  • 반드시 모든 지원 라이브러리는 동일합니다 있는지 확인하십시오 compileSdkVersion당신의 build.gradle(Module:app)내 경우가 있습니다 26.여기에 이미지 설명 입력

  • defaultConfig 카테고리에서 multiDexEnabled true를 입력 하십시오 . 이것은 중요한 부분입니다.multiDexEnabled 트루 이미지

  • 파일로 이동 | 설정 | 빌드, 실행, 배포 | 즉시 실행 을 클릭 핫 스왑 / 비활성화 즉시 실행을 사용하려고 ... 그리고 좋아 핫스왑으로 Instant Run 활성화 ... 이미지

  • Sync 당신의 프로젝트.

  • 마지막으로 빌드로 이동 | Rebuild Project를 클릭합니다 .

  • 참고 : 프로젝트 다시 빌드는 먼저 프로젝트를 정리 한 다음 빌드합니다.


이것을 gradle에 추가하십시오.

    android {
      defaultConfig {
        multiDexEnabled true
        }
   }

"Build-> Clean Project"를 시도해보십시오. 그것은 나를 위해 문제를 해결했습니다.


해결:

이 링크를 참조 하세요 : minSdkVersion 에 따라 경고를 끄는 다양한 옵션이 있으므로 20 이하로 설정되어 있습니다 .

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

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

당신이있는 경우 20 이상의 minSdkVersion의 이상을 당신의 build.gradle 세트 사용에 경고를 종료하려면 다음을 수행하십시오

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

다음과 같이 종속성을 업데이트하십시오.

     dependencies {
        implementation 'com.android.support:multidex:1.0.3'
     }

다시 한 번 유일한 차이점은 종속성의 키워드입니다.

minSdkVersion 20 미만 : 컴파일 사용

20 이상의 minSdkVersion : 구현 사용

  1. 도움이 되었기를 바랍니다. 문제가 해결 되었으면 찬성 해주세요. 시간을 내 주셔서 감사합니다.
  2. 또한 이것이 발생 하는 이유대한 자세한 정보 는 링크의 첫 번째 단락을 읽으십시오. 이유를 자세히 설명합니다. 그리고 무엇이 경고는 것을 의미한다.

나를 위해, 추가

multiDexEnabled true

packagingOptions {
        exclude 'META-INF/NOTICE' 
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
    }

응용 프로그램 수준 Build.gradle의 파일은 문제를 해결


multiDexEnabled true를 포함하여 위에서 언급 한 많은 솔루션을 시도했지만 그 중 어느 것도 나를 위해 일하지 않았습니다.

나를 위해 일한 해결책은 다음과 같습니다.이 코드를 app \ build.gradle 파일에 복사하십시오.

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support' && requested.name != 'multidex') {
            details.useVersion "${rootProject.ext.supportLibVersion}"
        }
    }
}

코드를 실행하기 전에 gradlew를 깨끗하게 실행하십시오.


나에게도 똑같은 일이 일어 났고 내가 AS 3.0.1로 업데이트하는 중이라는 것을 알았고 업데이트를 수행하고 앱을 정리하고 다시 빌드 한 후 모든 것이 수정되었습니다.


나를 위해이 오류를 수정 한 것은 내 앱의 gradle 종속성에서 한 줄을 변경하는 것입니다.

from this:

compile('com.google.android.gms:play-services-gcm:+') {
    force = true
}

To this:

compile('com.google.android.gms:play-services-gcm:11.8.0') {
    force = true
}

Use multiDexEnabled true as below.

{
 minSdkVersion 17
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

and

implementation 'com.android.support:multidex:1.0.3'

this Solution worked for me.


Also be sure your app is subclassing MultiDexApplication

import android.support.multidex.MultiDexApplication

class App : MultiDexApplication()

or if not subclassing Application class, add to AndroidManifest.xml

<application
  android:name="android.support.multidex.MultiDexApplication"

Are you in between SDK or platform updates? If yes complete those completely and then try to continue. I normally update the individual packages that need to be updated as to taking the entire update which could go up to 2.5 GB sometimes. Doing this complete update sometimes fails. I had a number of SDK updates once I upgraded to Android Studio 3.0 and was getting the above error since all packages had not been updated. Once I updated all packages the above error was gone.


In my case changing firebase library version from 2.6.0 to 2.4.2 fixed the issue


For me, the problem was the use of Java 1.8 in a module, but not in the app module. I added this to the app build gradle and worked:

android{
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

Same problem. I have enabled multidex: defaultConfig { applicationId "xxx.xxx.xxxx" minSdkVersion 24 targetSdkVersion 26 multiDexEnabled true

I have cleared cache, ran gradle clean, rebuild, make, tried to make sure no conflicts in imported libraries (Removed all transitive dependencies) and made all updates. Still:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

Turns out the build did not like: implementation 'org.slf4j:slf4j-android:1.7.21'


When the version of Android Studio is 3.0.1, Gradle Version is 4.1 and Android PluginVersion is 3.0.0, it will encounter this problem. Then I downgrade Gradle Version is 3.3, Android Android is zero, there is no such problem.


I had this when requested SDK version didn't match the dependencies. You can click the line highlighted and fix this clicking the red light bulb. No need to find the actual version, just let the IDE figure it out for you. And add google repo to maven config.


I was receiving the same error and in my case, the error was resolved when I fixed a build error which was associated with a different build variant than the one I was currently building.

I was building the build variant I was looking at just fine with no errors, but attempting to debug caused a app:transformDexArchiveWithExternalLibsDexMergerForDebug error. Once I switched to build the other build variant, I caught my error in the build process and fixed it. This seemed to resolve my app:transformDexArchiveWithExternalLibsDexMergerForDebug issue for all build variants.

Note that this error wasn't within the referenced external module but within a distinct source set of a build variant which referenced an external module. Hope that's helpful to someone who may be seeing the same case as me!


I Have Done and fixed this issue by just doing this jobs in my code

Open ->build.gradle Change value from

compile 'com.google.code.gson:gson:2.6.1'

to

compile 'com.google.code.gson:gson:2.8.2'

To remove this Dex issue just implement one dependency. This issue occur when we are using multiple different service from the same server. Suppose we are using ads and Firestore in a project and both have a repository maven. so we need to call different data with on repository we need dex dependency to implement. The new update Dependency:-

 implementation 'com.android.support:multidex:1.0.3'

I'm sure it will resolve your issue permanent


1)Please add multiDexEnabled true
2)if you get compilation error then check your app level build.gradle weather same dependencies are implemented with different versions.
3)Remove one if you find same dependencies.

android { compileSdkVersion 28 defaultConfig {

    minSdkVersion 17
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
hope it works fine :) Happy Coding

The easiest way to avoid suck kind of error is:

-Change library combilesdkversion as same as your app compilesdkversion

-라이브러리의 supportLibrary 버전을 build.gradle (app)과 동일하게 변경하십시오.


이것이 나를 위해 일하는 것입니다. 깨끗한 준비 및 실행.

cordova clean android;
ionic cordova prepare andriod;
ionic cordova run andriod;

도움이되기를 바랍니다.


모듈 레벨 build.gradle파일로 이동 하여 코드에 다음 행을 추가하십시오.

    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

그것은 문제를 쉽게 해결했습니다. 문서를 확인하십시오.

참고 URL : https://stackoverflow.com/questions/47079113/android-studio-3-0-execution-failed-for-task-unable-to-merge-dex

반응형