ClassLoader to replace a pre-loaded class?

Viewed 1662

General question: Is it possible to use a ClassLoader to replace a pre-loaded (by the system, e.g. found in Android's %android%/frameworks/base/preloaded-classes file) class?

Specific: I am attempting to use the DexClassLoader to replace a class found in android.net.* before creating a WebView in my application. I can get a Class object, but getMethods() for example gives me an array I'd expect in the unmodified/original class implementation. Is this due to the preloaded-classes system?

Basic setup & pseudo code:

  1. Modify android.net.* class, adding a few test methods/etc.
  2. Compile and end up with classes.dex
  3. jar cf mytest.jar classes.dex
  4. Include mytest.jar in APK assets
  5. Create DexClassLoader and get Class via loadClass()
  6. getMethods() on Class object returns an array I'd expect to see without modifications present in #1

I can provide more details on the setup I'm using and code if needed.

1 Answers
Related