Search code examples
androidandroid-library

Java library (.jar) with resources in Android project


I want to use a regular Java library in an Android project. That library's .jar includes resources (text files) that are used by the library internally, i.e. it accesses these resources via a relative path within the .jar.

However, if I run the application on an Android device, I get an IOException telling me that the respective resource was not found.

Is it possible to have the library access its resources when run on the Android Dalvik VM? If so, what would I have to specify in my project?


Solution

  • 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." (from This SO answer)