本文介绍了自定义类加载/压倒一切的Andr​​oid原生班的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要目标是覆盖Android系统级(活动,视图等)和我自己的实现。

Main goal is to override Android system class (Activity, View etc) with my own implementation.

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

ClassLoader的自定义类加载实现,加载非系统类(自定义类)的作品。

ClassLoader for custom class loading is implemented, loading non-system class (custom class) works.

但是,当我尝试加载活动与我的实现 - 它不会加载,因为类加载器已经有这个类在它的缓存:

But when I try to load Activity with my implementation - it doesn't load, because ClassLoader already has this class in its cache:

/**
 * 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);
}

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

How can I change class loader to inject my own class instead of system?

推荐答案

我发现的。我知道这是相当对堆栈溢出的政策来发布链接,但文字是太大而被转移。

I have found this solution from a blog post. I know it is rather against stack overflow policies to post a link but the text is too big to be transfered.

我们的想法是写一些C code,它覆盖了低级别的类加载机制,从而覆盖执行方法的方法。我希望这可能是一些帮助的人。

The idea is to write some C code that overrides the low-level class loading mechanism and thus override the way a method is executed. I hope this might be some help to someone.

这篇关于自定义类加载/压倒一切的Andr​​oid原生班的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 07:50