如何在运行时从Assets文件夹加载JAR [英] How to load a JAR from Assets folder at runtime

查看:378
本文介绍了如何在运行时从Assets文件夹加载JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时从android应用程序的assets文件夹加载jar文件。从资产文件夹加载是我的要求。有没有办法做到这一点。请帮助..

How to load a jar file from assets folder of android application during run time. Loading from assets folder is my requirement. Is there any way to do this. Please help ..

推荐答案

我得到了答案。我在这里添加这个答案。因为这可能对其他人搜索有帮助。

I got the answer.I am adding this answer here. Because this may be helpful to some others searching.

有完成此步骤的步骤。


  1. 您必须将JAR文件的副本复制到应用程序的私有内部存储中。

  1. You have to make a copy of your JAR file into the private internal storage of your aplication.


  1. 使用android文件夹中的 dx 工具,您必须生成与JAR文件关联的classes.dex文件。 dx工具将位于 /android-sdks/build-tools/19.0.1 位置(Dalvik VM需要此文件,dalvik VM无法读取jar))

  1. Using the dx tool inside the android folder, you have to generate a classes.dex file associated with the JAR file. The dx tool will be at the location /android-sdks/build-tools/19.0.1 (this file is needed by the Dalvik VM, simply jar can not be read by the dalvik VM))

使用也位于同一位置的 aapt 工具命令,您必须将classes.dex添加到JAR文件中。

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

可以使用DexClassLoader动态加载此JAR文件。

This JAR file could be loaded dynamically using DexClassLoader.

如果您正在制作您自己的库中的任何一个JAR,每当库源代码发生更改时,您必须执行此步骤(1-4)。因此,您可以通过创建shell脚本(在Mac / Linux / Ubuntu中)或批处理脚本(在Windows中)来自动执行此步骤。您可以参考此链接以了解如何编写shell脚本。

If you are making a JAR from any one your own library, you have to do this steps (1-4) every time when there is a change in your library source code. So you can automate this steps by creating a shell script(in Mac/Linux/Ubuntu) or batch scripts(in Windows). You can refere this link to understand how to write shell scripts.


注意:实现此方法的一种情况是,当它是无法将JAR文件直接添加到核心项目的构建路径,需要在运行时动态加载。在正常情况下,JAR文件可以添加到构建路径中。

Note : One situation for implementing this method is, when it is impossible to add the JAR files directly to the build path of core project and need to be loaded dynamically at run time. In normal cases the JAR files could be added to the build path.

请查看此链接以获取详细代码和实施。

please check this link for the detailed code and implementation.

如何在运行时加载jar文件

Android:如何从JAR动态加载类文件?

这篇关于如何在运行时从Assets文件夹加载JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆