3

My task is to dynamically instantiate classes in my android app from a jar file that has been written/compiled by someone else. I used this example: Is it possible to dynamically load a library at runtime from an Android application? to get started, it works great with APK files but I'm unable to use DexClassLoader to load classes from JAR files. I think its because my JAR file doesn't have classes.dex.

I'm trying to use "dx --dex --keep-classes --output=newjar.jar my.jar" on a simple hello world java class, but the generated JAR only contains my .class files and doesn't have classes.dex

Question 1: Is it possible to use android dx tool to generate classes.dex for non-android java files?

Question 2: What are the minimum requirements for dx tool to generate classes.dex?

Community
  • 1
  • 1
  • Well I'm not sure why my dx tool was working before, but it does now. I'll answer my own questions here: – Aleksey Khivrenko Feb 18 '16 at 01:24
  • 2
    1. yes, it is possible. I used "dx --dex --output=newJar.jar old.jar" (old.jar was previously compiled for a java application) and I got my classes.dex inside newJar.jar \n\r 2. minimum requirements are dx.bat, dx.jar, find_java.bat, find_java32.exe, find_java64.exe which are all found in the android sdk. In fact I pulled these 5 files and generated the classes.dex file on a fresh machine (after installing java8). – Aleksey Khivrenko Feb 18 '16 at 01:30
  • it would be great to add this as an abstract answer to the question. :) – node_analyser May 23 '21 at 08:12

0 Answers0