自定义类加载/覆盖 Android 原生类

2024-02-21

主要目标是用我自己的实现覆盖 Android 系统类(Activity、View 等)。

http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html

实现了ClassLoader用于自定义类加载,加载非系统类(自定义类)的工作。

但是,当我尝试使用我的实现加载 Activity 时,它不会加载,因为 ClassLoader 的缓存中已经有此类:

/**
 * Returns the class with the specified name if it has already been loaded
 * by the virtual machine or {@code null} if it has not yet been loaded.
 *
 * @param className
 *            the name of the class to look for.
 * @return the {@code Class} object or {@code null} if the requested class
 *         has not been loaded.
 */
protected final Class<?> findLoadedClass(String className) {
    ClassLoader loader;
    if (this == BootClassLoader.getInstance())
        loader = null;
    else
        loader = this;
    return VMClassLoader.findLoadedClass(loader, className);
}

如何更改类加载器以注入我自己的类而不是系统类?


我已经发现这个解决方案 http://shadowwhowalks.blogspot.gr/2013/02/android-replacing-system-classes.html来自博客文章。我知道发布链接是相当违反堆栈溢出政策的,但文本太大而无法传输。

这个想法是编写一些覆盖低级类加载机制的 C 代码,从而覆盖方法的执行方式。我希望这对某人有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

自定义类加载/覆盖 Android 原生类 的相关文章

随机推荐