javaandroidjardexdx

How to merge two dex files from command line


From last few days I was getting in depth How actually android studio works behind the hood.

I explored many tools like aapt, dx, dalvikvm and many others.

Now I have a very simple problem. I have a jar file (called abc.jar for example) which is about 2.7 MB and I also have a very small java code in my application.

First i compiled my source code into .class files. Then I dexed my .class files and abc.jar file into .dex file. It took about 40 to 50 secs. But i was able to run the application successfully.

Command that I used to dex my source code and abc.jar

dx --dex --output=classes.dex abc.jar *class_files*

Now the problem is whenever i modify my code I have to redex all the stuff (including the abc.jar) which takes years. What I now want is that Is there anyway by which i have to just dex abc.jar once and then whenever i make changes to my code i would just take the dexed version of abc.jar and add it to my source code.

Like android studio does. If you add some external libaries, at first it takes some time to dex those libaries but after that whenever you modify your code it does not have to redex all the libaries from scratch instead it just takes the pre-dexed libaries and adds them to the apk.

Thank you in advance


Solution

  • 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