简体   繁体   English

带有 Android 项目资源的 Java 库 (.jar)

[英]Java library (.jar) with resources in Android project

I want to use a regular Java library in an Android project.我想在 Android 项目中使用常规 Java 库。 That library's .jar includes resources (text files) that are used by the library internally, ie it accesses these resources via a relative path within the .jar.该库的 .jar 包括库内部使用的资源(文本文件),即它通过 .jar 中的相对路径访问这些资源。

However, if I run the application on an Android device, I get an IOException telling me that the respective resource was not found.但是,如果我在 Android 设备上运行该应用程序,则会收到一个 IOException,告诉我找不到相应的资源。

Is it possible to have the library access its resources when run on the Android Dalvik VM?在 Android Dalvik VM 上运行时,是否可以让库访问其资源? If so, what would I have to specify in my project?如果是这样,我必须在我的项目中指定什么?

Unfortunately it can't be done.不幸的是,这是做不到的。 "In general you cannot distribute your own package as easily as you would expect. The main problem is the autogenerated R file. You probably make some references to it - you have your layouts and drawables. User of your library will have his own R file - containing ids for his resources, not for the ones your library provides." “一般来说,您无法像预期的那样轻松分发自己的包。主要问题是自动生成的 R 文件。您可能会引用它-您有自己的布局和可绘制对象。您的库的用户将拥有自己的 R 文件- 包含他的资源的 ID,而不是你的图书馆提供的资源。” (from This SO answer ) (来自这个 SO 答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM