ClassNotFound exception fixed when loading class from loaded dex file

I am trying to implement a hot-fix mechanism in my Android application. After I looked for time to search, here is what I did:

  • I generated a file dynamic.jarwith the classes I want to fix. (I use eclipse and ADT)
  • Using dx --dex --output=patch.jar dynamic.jar, I managed to create a jar file containingclasses.dex
  • In my Android code, I loaded the class using DexClassLoader: new DexClassLoader(patchFile.getAbsolutePath(), outputFolder.getAbsolutePath(), null, getClassLoader().getParent()(Note that I am using getParent ())
  • I checked that the file was .dexsuccessfully extracted inoutputFolder
  • I changed the classloader to my custom classloader through reflection. And I checked that the custom classloader is working
  • When I try to load a class from CUSTOM_LOADER.loadClass(className), I gotClassNotFoundException

So I wonder what happened? I used DexFileto list all the classes in this file .dex, and a new class appeared. Is it even possible to download a subset of compiled classes from the Internet?

Thanks in advance.

+4
source share

All Articles