0
  • I am using DexClassLoader to load a jar file translated to DEX from Java jar, using the dx tool.
  • The jar file is in: /storage/sdcard0/Download/br_applications/calculator.dx.jar
  • I have permissions:
  • My code is (+/-):

        String url_jar_path = "/storage/sdcard0/Download/br_applications/calculator.dx.jar";
        String         dex_dir = context.getDir("dex", 0).getAbsolutePath();
        ClassLoader    parent  = Cargar_jars.class.getClassLoader();
        dexclassloader = new DexClassLoader(url_jar_path, dex_dir, null, parent);
        main_class = "browserun.main.Mains";
        Class clase = dexclassloader.loadClass(main_class);
        Class[] arguments_array = new Class[1];
        arguments_array [0] = String [].class;
        Method method_main = clase.getMethod("main", arguments_array);
        String [] params_array = { "param_1" };
        Object[] arguments_main_array = new Object[1];
        arguments_main_array [0] = params_array;
        method_main.invoke (null, arguments_main_array);
        /* Here I got Exception: Method not found. */
    
  • I have tried with .apk file. And the result is worst yet. I do not get load the class...
  • I have tries with .aar file. And the result was bad.
  • ¿May anybody give me a code working?
  • I am using Android Studio, and I create the jar files using a fake apk applications with a module, which is the Java Jar. The I use the dx tool to create the dx.jar file: dx --dex --output calculator.dx.jar calculator.jar Thanks.

1 Answers1

0

I made a change:

method_main.invoke (null, arguments_main_array[0]);

instead:

method_main.invoke (null, arguments_main_array);

I had something wrong in the code of the called method in the external jar.

If I use:

dex --dex --output <jar target> <jar origin>

I got a valid jar.

But the code called worked before and not now... And I cannot debug it... :(