Com android builder dexing dexarchivemergerexception error while merging dex archives

I made: In "Settings"->"Android SDK"->"SDK Tools" Google Play services is checked and installed v.46 Removed folder /.gradle "Clean Project" "Rebuild Project Error is: Error:Execution failed for...

I made:

  • In «Settings»->»Android SDK»->»SDK Tools» Google Play services is checked and installed v.46
  • Removed folder /.gradle
  • «Clean Project»
  • «Rebuild Project

Error is:

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

Project build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

        classpath 'com.google.gms:google-services:3.1.0'
    }
}

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

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

App build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.asanquran.mnaum.quranasaanurdutarjuma"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 3
        versionName "1.3"
        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.+'


    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-ads:11.4.2'
    compile 'com.github.barteksc:android-pdf-viewer:2.3.0'
    compile 'org.apache.commons:commons-io:1.3.2'
    compile 'com.google.firebase:firebase-ads:11.4.2'
    compile 'com.google.firebase:firebase-messaging:11.4.2'
    compile 'com.google.firebase:firebase-storage:11.4.2'
    apply plugin: 'com.google.gms.google-services'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

Jonas Praem's user avatar

Jonas Praem

2,2664 gold badges29 silver badges51 bronze badges

asked Oct 27, 2017 at 14:20

Nauman Shafique's user avatar

Nauman ShafiqueNauman Shafique

4331 gold badge6 silver badges15 bronze badges

9

  1. Go to <project>/app/ and open build.gradle file
  2. Add the following line to the defaultConfig and dependencies sections
android {
  ...

  defaultConfig {
    ...
    multiDexEnabled true // ADD THIS LINE
  }
}

...

dependencies {
  ...
  implementation 'com.android.support:multidex:1.0.3'  // ADD THIS LINE
}

answered Jun 16, 2020 at 19:19

Ilker Cat's user avatar

3

I know it’s too late to update.I had same issue on my project.

Possible Reasons

  1. If you have added module in your project and that module has support libraries or any google play services libs which has different version then your app.
  2. If you are using any open source library in your project and that library internally using any of libraries that your are also using in your project.

Solutions

  • If it is case 1 in your project then update your library versions and make it same in your project and module.
  • Check your dependencies tree using below command and see if any mismatch in dependencies.

    ./gradlew :app:dependencies
    
  • You can exclude particular module from any dependencies like below.

    implementation('com.google.android.ads.consent:consent-library:1.0.4') {
      transitive = true
      exclude group: "com.android.support"
    } 
    
  • In above example, It will exclude the com.android.support group from consent-library dependencies.

  • You can also remove particular module as well.

     compile ('junit:junit:4.12'){
      exclude group: 'org.hamcrest', module:'hamcrest-core'
      }
    
  • In above example it will exclude hamcrest-core from org.hamcrest.

answered Jun 28, 2018 at 17:12

VP4Android's user avatar

VP4AndroidVP4Android

5764 silver badges16 bronze badges

1

I got the same problem, adding sourceCompatibility and targetCompatibility to my build.gradle helped me:

android {
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

answered Nov 14, 2017 at 21:00

Philipp Cherubim's user avatar

0

I was having a fit with this, and none of the answers I found worked. Finally found a solution — sharing it here although I can’t tell you definitively how to find which is the offending dependency — maybe you’ll have to do some trial and error.

In my build.gradle (Module:app) I added this exclude clause:

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

answered Nov 2, 2017 at 18:25

veggiebenz's user avatar

veggiebenzveggiebenz

3794 silver badges12 bronze badges

I did exact as the hint in the image except changed 11.0.4 to 11.8.0

compile 'com.google.android.gms:play-services-base:11.8.0'
compile 'com.google.android.gms:play-services:11.8.0'

Unable to merge dex

clemens's user avatar

clemens

16.2k11 gold badges46 silver badges62 bronze badges

answered Jan 18, 2018 at 5:18

mohammed alshaarawi's user avatar

I think it was due to Android Studio’s latest version (at that time).
I tried it after a long time then the issue gone.

answered Nov 23, 2019 at 5:53

Nauman Shafique's user avatar

Nauman ShafiqueNauman Shafique

4331 gold badge6 silver badges15 bronze badges

while creating Flutter Project, I encountered this issue. What I did is, opened MyProject/android/app/build.gradle file and added multiDexEnabled true inside defaultConfig tag as given below:

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "Your Application ID Here"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

answered Jun 27, 2020 at 15:41

Hanny's user avatar

HannyHanny

1,31215 silver badges20 bronze badges

When the same issue appeared, my build.gradle already had the following was already there:

android {
  ...

  defaultConfig {
   ...
  multiDexEnabled true 
   }
}

...

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

I cleaned the project, and then run build again, and the issue was gone.

answered Jan 16, 2021 at 17:04

Fahima Mokhtari's user avatar

Fahima MokhtariFahima Mokhtari

1,4811 gold badge15 silver badges29 bronze badges

3

in my case i change all com.android.support: libraries to 27.1.0 and it works

answered Feb 28, 2018 at 12:56

Marriage's user avatar

MarriageMarriage

4713 silver badges15 bronze badges

error while merging dex archieve
enable multidex android

Hi Guys, Welcome to Proto Coders Point, In this tutorial, we will checkout & solve the common error that “error while merging dex archives”.

Video Tutorial to solve the same

The error says: DexArchiveMergerException

Cannot fit requested classes in a single file: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

so before looking into how to solve multi dex error, let’s learn basic about DEX(Dalvik Executable).

What is the dex file? Understanding Multidex in android

In Java, your code is converted from .java to .class file during compile time, so that our machine can understand the .class file but in android, the java code is compiled into DEX(Dalvik Executable) file so that our Android machine can understand it.

This article is for android/flutter developers who face DEX error “cannot fit requested classes in a single file: error while merging dex archieve“.

error while merging dex archieve
error while merging dex archieve

The error itself says you, why you are facing “multi Dex error”, The number of methods references in a .dex file cannot exceed 64K (# 68563 > 65536).

A Single DEX file limits the number of methods referenced, A single DEX file is limited to 64K i.e. 65536, which simply means that you cannot create more than 65536 methods in a single DEX file(“cannot fit requested classes in a single file“).

usually, this DEX error occurs when a developer adds external android/flutter libraries,

So, sometimes by adding external libraries to your android/flutter projects, if your project merged app exceeds 65536 methods, than you will encounter a build error as mentioned above “error while merging dex archieve“.

Ways to enable multidex support in android studio project

Solution 1: Clean project and invalidate caches & restart

Once you add any external libraries in your android studio project always keep habit to clean project and invalidate cache restart.

Step 1: Menubar -> Build -> Clean Project then Rebuild project.

Step 2: Menubar -> Invalidate Caches/Restart.

Solution 2: Enable multidex for app over 64K methods

To enable multidex, if you are not using AndroidX, you need to add deprecated library in dependency

dependencies {
    implementation "com.android.support.multidex: 1.0.3 " //add this
    
}

By adding above multidex it will become a primary DEX file of your app.

if your minSdkVersion is set to 21 or higher, The Multidex is been enabled by default while creating new project, if not,

then do the followng steps:-

Step 1: modify Module level app/build.gradle

android {
    defaultConfig {
        applicationId "com.example.flutter_app_simple"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true //add this line
    }
}

dependencies {
    implementation "com.android.support.multidex: 1.0.3"  // add this line

}

Step 2: Add multidex in manifest <application> tag

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="androidx.multidex.MultiDexApplication" >  <!-- add this line -->
        ...
    </application>
</manifest>

The issue I believe is that since we did not define the default color in the config, it cannot match the ID to the resource, and fails. I just updated the «getColor» method and added a try/catch for the resource. Seems to work fine. The final edit I made was as follows:
In the FirebaseMessagingPluginService.java, the OnCreate method:

public void onCreate() {
this.broadcastManager = LocalBroadcastManager.getInstance(this);
this.audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
this.notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
this.defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Context context = getApplicationContext();

    try {
        ApplicationInfo ai = getPackageManager().getApplicationInfo(getApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
        this.defaultNotificationColor = 0xFF000000;

        try{
            this.defaultNotificationColor = ContextCompat.getColor(context, ai.metaData.getInt(NOTIFICATION_COLOR_KEY));
        }
        catch(Resources.NotFoundException e){
            Log.e(TAG, "Failed to find resource", e);
        }

        if (this.defaultNotificationIcon == 0) {
            this.defaultNotificationIcon = ai.icon;
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Failed to load meta-data", e);
    }
}

#flutter #dart

Вопрос:

У меня возникла эта ошибка при запуске приложения Flutter. Что я сделал, так это обновил flutter с sdk: «>=2.7.0 ><3.0.0» до sdk: «>=2.12.0 <3.0.0» до sdk: «><3.0.0», но появилось много ошибок, поэтому я вернулся к версии sdk -> sdk: «<3.0.0″, но появилось много ошибок, поэтому я вернулся к версии sdk ->>=2.7.0 <3.0.0», но появилось много ошибок, поэтому я вернулся к версии sdk ->> Затем я сделал Flutter Чистым, и когда я снова построил проект, я получил эти ошибки.

 Launching libmain.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
    at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:104)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
    at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:444)
    at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:335)
    at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:47)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:65)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:61)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:56)
    at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:215)
    at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:210)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.file.NoSuchFileException: F:epicarebuildappintermediatesexternal_libs_dexdebugmergeExtDexDebugout
    at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
    at sun.nio.fs.WindowsFileAttributeViews$BasicWithKey.readAttributes(WindowsFileAttributeViews.java:164)
    at sun.nio.fs.WindowsFileAttributeViews$BasicWithKey.readAttributes(WindowsFileAttributeViews.java:153)
    at java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:225)
    at java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:282)
    at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:328)
    at java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:72)
    at java.nio.file.Files.walk(Files.java:3574)
    at java.nio.file.Files.walk(Files.java:3625)
    at com.android.builder.dexing.DirDexArchive.getFiles(DirDexArchive.java:67)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:98)
    ... 34 more


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Exception: Gradle task assembleDebug failed with exit code 1
 

Ответ №1:

Добавьте multiDexEnabled true в свой app/build.gradle

 defaultConfig {
    (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.arslan.example"
    // I suggest you to increase minSdkVersion from 16 to 21
    minSdkVersion 21
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    //Add this line here...
    multiDexEnabled true
}
 

Дайте мне знать, помогло ли это решение решить вашу проблему

Понравилась статья? Поделить с друзьями:
  • Column count doesn t match value count at row 1 как исправить
  • Column ambiguously defined oracle ошибка
  • Color registration automatic adjustment error 2
  • Color plane registration sensor error
  • Color laserjet pro mfp m180n error 11