Most apk files, when disassembled, produces 2 dex files instead of one. However since IDA Pro only allows the loading of one dex file at a time,it may result in missing information as a result of the other dex file not being loaded. Are there any way to combine these 2 dex files into one so that I can load the complete dex file into IDA Pro? I tried disassembling both dex files to smali files and then using smali.jar to combine these smali files again into one single dex file but I am facing the following error:

Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred
while writing code_item for method Ladyen/com/adyencse/pojo/Card;->serialize(Lja
        at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java
        at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:267)
        at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:245)
        at org.jf.smali.Smali.assemble(Smali.java:130)
        at org.jf.smali.AssembleCommand.run(AssembleCommand.java:96)
        at org.jf.smali.Main.main(Main.java:99)
Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at
code offset 0x2
        at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1091)
        at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java
        ... 5 more
Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range:
        at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:11
        at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:
        at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1051)
        ... 6 more
  • You are hitting the 64k limit of the Dalvik instruction format. 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. It will work, though, if you cut unnecessary pieces before running the smali assembler (did someone say Google Play Serviced Client Library?) Commented Aug 25, 2017 at 21:47
  • You should give a try to JEB Decompiler. It can merge the classesX.dex files of a multi-DEX APK into a single DEX, regardless of reference count limitations.
    – Nick
    Commented Sep 12, 2017 at 16:37

1 Answer 1


Personally, I wouldn't be using IDA Pro (essentially a tool optimised for decompiling real binaries) for decompiling Java. Use Jeb or something made specifically for Java, or even better, for Android.

I admit I don't like the subscription licensing model of the new Jeb very much, but "horses for courses". There are likely other Android (Java) decompilers that can handle multi-dexes. Dex2Jar+whatever? Jadx? (I don't know)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.