How to load JAR from Assets folder at runtime

How to download jar file from Android application resource folder during runtime. Downloading from the resource folder is my requirement. Is there any way to do this. Please, help..

+6
android jar runtime
Jun 10 '14 at 7:22
source share
1 answer

I got an answer. I am adding this answer here. Because it can be useful for finding others.

There are steps to achieve this.

  • You must make a copy of your JAR file in the private internal storage of your application.

    1. Using the dx tool inside the android folder, you should generate the classes.dex file associated with the JAR file. The dx tool will be located at /android-sdks/build-tools/19.0.1 (this file is needed by VM Dalvik, just jar cannot be read by VM-dalvik))

    2. Using the aapt tool command , which is also located inside the same location, you must add the classes.dex file to the JAR file.

    3. This JAR file can be loaded dynamically using DexClassLoader.

    4. If you are making a JAR from any of your own libraries, you must do these steps (1-4) every time you change the source code of your library. This way you can automate these steps by creating a shell script (on Mac / Linux / Ubuntu) or batch scripts (on Windows). You can link to this link to understand how to write shell scripts.

Note One of the situations for implementing this method is the impossibility of adding JAR files directly to the build path of the main project and it must be dynamically loaded at run time. In normal cases, JAR files can be added to the build path.

please check this link for detailed code and implementation.

How to load jar file at runtime

Android: how to dynamically load classes from a JAR file?

+5
Jun 10 '14 at 9:09
source share



All Articles