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

dex2jar multiple dex files
android dex
dex tool android
classes2 dex
androidx multidex
vm has multidex support, multidex support library is disabled

I am doing some hacking on Jan Berkel's SBT Android Plugin and I was wandering if there is a way to merge multiple .dex files into one .dex file that will contain all of them.

For example, if I have this:

classes1.dex
classes2.dex
classes3.dex

Is there any way to merge them using Scala (in some acceptable time) to one single classes.dex file that will contain all 3 of them and have a following structure:

classes.dex
|-- classes1/...
|-- classes2/...
\-- classes3/...

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

android, Is there a way to merge two or more .dex files into one .dex file using Scala? - android. You can not have more than 64k of methods, member variables or types used within one dex file. That's exactly the reason why multidex was introduced (that is, more than one dex file in a single APK file). Whatever you do to merge the two files, it will fail, because the app is too big to fit into a single dex file.

I found a way which don't need to compile from source, just use the SDK compiled jar.

java -cp dx.jar com.android.dx.merge.DexMerger output.dex input1.dex input2.dex

The dx.jar is located in Android SDK dir, like android\sdk\build-tools\26.0.2\lib. The dex file have 64k method limit, so it can't hold so much in one dex file.

How can I reduce the number of dex files in my app, is there way merge them using scala (in acceptable time) 1 single also, if works​, merging more 2 dex files should same max(max(a, b), c),  DBX Merge tool provides a facility to merge two (or more than two) DBX files into a single or common DBX file. If you have multiple DBX file in archive then Combine DBX files. Join DBX Files (s) Join DBX files is a way to save you all files or folders in a separate manner without combining same named folders.

it's working. r22 uses this way to pre-dex android-support-v4.jar and annotations.jar into dex format first. Ant then use dx.bat to merge them with the compiled .class files.

Results for r:bazel, Infact when minsdk is 4.0 it's one dex file. For now please change the minsdk as the workaround. 46 Is there a way to get a list of all classes from a .dex file? 8 Is there a way to merge two or more .dex files into one .dex file using Scala?

First zip them individually like classes1.dex.zip, classes2.dex.zip, classes3.dex.zip and then run following

java -jar dx.jar --dex --output=classes.dex.zip classes1.dex.zip classes2.dex.zip classes3.dex.zip

That's it. Now you have a classes.dex in classes.dex.zip with classes1.dex.zip classes2.dex.zip classes3.dex.zip are merged.

Share Android source code and resources using library projects , 37: * Merger for {@code .dex} files into larger chunks subject to {@code .dex} file limits 141: help = "Allow more than one .dex file in the output.") 27: * Helper to track how many unique field and method references we've seen in a given set of .dex 37: * Creates an indexer instance from two backing maps. In your Windows cmd.exe command-line, use the following single command to merge all text files in a directory into one new file: copy /b *.log newfile.log copy /a *.txt newfile.txt. The copy parameters /a and /b indicate ASCII text or BINARY files. This is ideal for combining multiple log files into one file for LogParser and IIS log forensics.

Top 50 Android Interview Questions You Must Prepare In 2020 , To enable sharing Android source code and resources, do one of the Including the .dex file of a library module into the .apk of the entire application The manifest file contains the information that is required to run the application (for more To have the manifest of a library module merged with the application manifest  To choose the merge option, click the arrow next to the Merge button and select the desired merge option. Once complete, the files are merged. Tip. If there are multiple files you want to merge at once, you can select multiple files by holding down the Ctrl key and selecting each file you want to merge.

scala-android/sbt-android-protify, An Activity is the screen representation of an application in Android. Below are the two methods which almost all subclasses of Activity will implement: What is the difference between File, Class, and Activity in android? Android programs are compiled into '.dex' (Dalvik Executable) files, which are  You can combine full sheets or merge selected cell ranges from multiple spreadsheets into one file. Excel has built-in options for data consolidation, but there are also a few handy add-ons for the application that you can merge sheets with. Copy and Paste Cell Ranges From Multiple Spreadsheets. The good old copy (Ctrl + C) and paste (Ctrl + V

Working of Dalvik Virtual Machine in Android, https://github.com/scala-android/sbt-android/blob/master/src/dex.scala#L185 since it's incompatible and do stuff how it wants or say that I have to disable this setting I guess there's a bug where the dex files have duplicates like 34 shards, and than straight after that - no code changes occurred - on ~protify it said: The tutorial shows three ways to combine Excel files into one: by copying sheet tabs, running VBA, and using the Copy Worksheets tool. It is a lot easier to process data in a single file instead of switching between numerous sources.

Comments
  • How would you import the DexBuffer, DexMerger and CollisionPolicy classes? The links are empty.