How to Merge Dex

How to merge two dex files from command line

Finally after days of research I found a way...

I juts used d8 as dx has been depreciated.

d8 dexfile1.dex dexfile2.dex

Output would be classes.dex

Is there a way to merge two or more .dex files into one .dex file using Scala?

OK, it seems I found something.

import com.android.dx.io.DexBuffer
import com.android.dx.DexMerger
import com.android.dx.merge.CollisionPolicy
...
val dexA = DexBuffer(File(classes1DexFilePath))
val dexB = DexBuffer(File(classes2DexFilePath))
val dexMerger = DexMerger(dexA, dexB, CollisionPolicy.FAIL)
val dexM = dexMerger.merge()
dexM.writeTo(File(classesDexFilePath))

Could anyone verify this is indeed working?

Also, if this works, then merging more than 2 dex files should be the same as Max(Max(A, B), C), providing you write a method that with a prototype

DexBuffer merge(DexBuffer dexA, DexBuffer dexB)

Sources:

DexMerger

DexBuffer

CollisionPolicy

Unable to merge dex

I had the same problem when I update from com.google.android.gms:play-services:11.2.2 to com.google.android.gms:play-services:11.4.0. This solved it for me:

  1. clean
  2. rebuild

Unable to Merge-Dex

The transform dex merger issue was persistent.. Until I added a dependency ::

implementation 'android.arch.lifecycle:extensions:1.1.0'

How to resolve Unable to merge dex

Use latest Dependencies for Lifecycle, including LiveData and ViewModel.

Try this

implementation 'android.arch.lifecycle:runtime:1.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

than Clean-Rebuild- Run your project

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

change to

compilsdkVersion 29  
minSdkVersion 15
targetSdkVersion 29

how solve merge dex?

Before you start adding multi dex and changing your application to a multidexapplication. Consider minimizing your dependencies to the dependencies you need. You are importing the entire google play services.

Consider only including the ones you need or you will defintely exceed the 65,536 method limitation which will make you compile slower and have to adjust your gradle properties to speed things up with more memory.

If you must do multi-dex then update your application extends MultiDexApplication as well as your gradle properties to increase memory, but hopefully you don't have to do that.

Try to fix the problem properly before you patch it ;).

However, if it is not a multi-dex issue, it could be an issue dexing repeat dependencies of different versions. Possibly your google play service. I would run assembleRelease --info and get more info.

In the meantime, try forcing the play lib version all the way through in your manifest with this exact line

 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"
tools:replace="android:value" />

inside the application tag

Unable to merge DEX in Android Studio 3.0.1 even after enabling multidex

This isn't a multidex problem...it's a dependency merge conflict issue.

By the looks of it one of your dependencies has a sub-dependency on CoordinatorLayout but has specified a different version from the one which you are using. You can fix this by using a resolutionStrategy in your build.gradle to define the version of the support library to use.

First make a variable to define your support library version:

ext {
supportLibVersion = "26.1.0"
}

Then update your dependences to use this variable rather than the hard coded value (note the double quotes):

implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"

Then you can add a resolutionStrategy to your build.gradle:

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

What this does is ask Gradle to ignore the version number specified in with the dependency and use your version.

Unable to merge dex error when building my android project

with support libraries 27.1.1 it builds:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.firebaseui:firebase-ui-storage:4.1.0'
implementation 'com.android.support:multidex:1.0.3'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
testImplementation 'junit:junit:4.12'
}

if not, add the whole DexArchiveMergerException and not only that notice, which tells nothing.



Related Topics



Leave a reply



Submit