Android dx usage

foobarometer picture foobarometer · Jul 20, 2012 · Viewed 7.7k times · Source

I have a jar file created out of an android application, because I marked it as "Is library" in eclipse at creation time. Now the DexClassLoader is not able to load this file because it doesn't have an entry marked classes.dex. This looks like a standard jar. How can I convert such a jar into a dexed jar with dx that DexClassLoader can load? Any help appreciated!

Answer

Iain picture Iain · Jul 20, 2012

You can use the dx tool from the sdk, from the command line. Something like:

dx --dex --output=dexed.jar hello.jar

Works for me. Integrating such things into your build process is something of a black art, largely involving hacking up the ant buildscripts provided by the SDK. If your library is only occasionally updated it might be viable to do it manually.

In my case, I keep the dexed.jar in my resources/raw folder. At runtime, I copy it from there into the filesystem, then pass the filesystem path to the DexClassLoader. It's... a little bumpy.