android防治方法被反射,通过去classLoader避免Android P反射限制后还原classLoader的方法...
本站寻求有缘人接手,详细了解请联系站长QQ1493399855
[Java] 纯文本查看 复制代码/**
* 恢复classloader:清除loader可能会造成问题
* (java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available)
* 反射完成后恢复loader
*
* @param cls 需要恢复Loader的类
*/
public static void restoreLoaderInClass(Class cls) {
try {
Field classLoaderField = Class.class.getDeclaredField("classLoader");
classLoaderField.setAccessible(true);
//If this object represents a primitive type or void, null is returned.
if (cls != null && !cls.isPrimitive() && classLoaderField.get(cls) == null) {
Log.w(TAG, "restoreLoaderInClass: classloader is null!");
classLoaderField.set(cls, Thread.currentThread().getContextClassLoader());
}
} catch (Exception e) {
Log.e(TAG, "restoreLoaderInClass: ", e);