G
G
gibbonchik2016-06-08 15:13:07
Java
gibbonchik, 2016-06-08 15:13:07

How can I change (add) the code to the .dex file on Android?

Good day!) I am writing a code compiler program for android. With the javassist library, I can add or change the function code of my dex file like this:

final ClassPool pool = ClassPool.getDefault();
pool.appendClassPath(new LoaderClassPath(getClass().getClassLoader()));
pool.appendClassPath("./android.jar");
final CtClass compiledClass = pool.get(targetClass);
final CtMethod method = compiledClass.getDeclaredMethod(targetMethod);
method.insertBefore("{ java.lang.System#out.println(\"doA() is called.\");}");
compiledClass.writeFile(targetFolder);

But for the functionality of exporting and importing my projects, I need to do this with dex files that will be saved on the sd card for example.
So here's the question. How can I add code to a .dex file that is separate from the application?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question