I am writing a tool library in which I would like to work both on the desktop and mobile (Android).
It performs the function of:
- Providing a primary that takes one parameter, the primary target class
- Install a class loader that intercepts all classes as they are loaded and executes them.
Same:
// Expects args[0] to contain the name of the INNER main public static void main(String[] args) throws Throwable { String className = args[0]; String [] newArgs = new String[0]; if(args.length > 1) { newArgs = Arrays.copyOfRange(args, 1, args.length-1); } System.out.println("Bootstrapping " + className); Loader s = new Loader(ClassLoader.getSystemClassLoader().getParent()); Class<?> c = s.loadClass(className); c.getDeclaredMethod("main", new Class[] { String[].class }).invoke( null, new Object[] { newArgs }); }
The question arises:
How can I do roughly the same for an Android app?
One idea is to change the android manifest to replace the existing actions with a βwrapperβ, and then install the class loaders and call the original underlying asset. Is there a better way?
source share