测试通过 哈哈
public static void setMinHeapSize(long size) {
try {
Class<?> cls = Class.forName("dalvik.system.VMRuntime");
Method getRuntime = cls.getMethod("getRuntime");
Object obj = getRuntime.invoke(null);// obj就是Runtime
if (obj == null) {
System.err.println("obj is null");
} else {
System.out.println(obj.getClass().getName());
Class<?> runtimeClass = obj.getClass();
Method setMinimumHeapSize = runtimeClass.getMethod("setMinimumHeapSize", long.class);
setMinimumHeapSize.invoke(obj, size);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}