The not outdated method
Just in case anyone stumbled on this question like I did, all of these answers are outdated by now (I'm only talking about the answers answered before this one in this question)
The current method to merge dex files is this:
d8 classes1.dex classes2.dex classes3.dex
dx
has been renamed as d8
Now it's a lot simpler and cleaner
d8
can be found (in windows) in C:\Users\$your_user\AppData\Local\Android\Sdk\build-tools\$version\d8
You can merge any amount of dex files together, but:
The maximum method amount of a dex file is 65,536 (Which is equal to 64K, A K is equal to a kilo which is equal to 1024)
If you face that problem then this link might be helpful. The conclusion of the link was that you should use the --multi-dex
option. So the command will look like this:
d8 --multi-dex classes1.dex classes2.dex classes3.dex
and that you need to add the line
multiDexEnabled true
in the module/build.gradle
file in the defaultConfig
so it would look like this:
android {
...
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
...
}
...
}
I hope this helped