A fat binary is a binary that can be run on more than one architecture. Basically, it consists of a program compiled twice, once for each architecture, then written to the same file. Probably the best known example is Apple's "universal" binaries, allowing programs to be compiled for both Intel and Power PC architectures, and run from the same executable file.
This was never an issue for Java, since Java runs on the JVM, allowing it to be run from any JVM-supported computer. However, Android is now very popular, and Android's VM (Dalvik), is not compatible with the JVM. Is there some way of compiling the code twice, and creating a class file that can be executed by both the JVM and Dalvik? And if not, is this even possible?
Answer: Yes.
You can create a universal
.jarfile that contains both JVM-friendly.classfiles and an Android-friendlyclasses.dexfile. Thedxtool included in the Android SDK will emit such files if you use the--keep-classescommand line option.Note that although such
.jarfiles can be consumed on JVMs and on Android, packaging code in this way is not very useful. Android applications are packaged as.apkfiles include an Android manifest XML file. They use Android-specific APIs likeActivitythat are not available on the JVM.A universal
.jarfile would mostly be useful if you wanted to do runtime class loading of a library.