I create an Android project for build my custom widget, and I want to export it as a jar for other project so that reuse them conveniently, but now a problem is, I can't use resources which is included in my custom widget jar, for example a png picture, it gets a null from the resource Id of class R! How can I sovle it?
Update question:
How can I parse LayerDrawable xml from assets folder in code?
3 Answers
You cannot export self-contained Android Library jar at this time and announced will be available in the future SDK release.
https://developer.android.com/guide/developing/projects/index.html#LibraryProjects
-
thx, but can I parse LayerDrawable xml from assets folder in code? how to do it?– Tim WongCommented Mar 27, 2012 at 2:00
-
do you mean LayerDrawable xml in Library project? you should access resources in Library when using Android Library project. Commented Mar 28, 2012 at 6:52
-
Is it possible to reference a library project with resources?– f470071Commented Oct 26, 2015 at 16:27
You cannot export the Android Project to Jar with Resources. What you can do is Make First Project as Library and then Add that to another project.
See Documentation Here shows how to Setup a Project as Library and use in another Project
-
while the page you linked to does state ''You cannot export a library project to a JAR file. A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.'' however developer blog says it now is possible. when i created a new android project and marked it as being a library, i found a .jar file in the bin directory of that project. however this jar did not include either the R class or any resource Commented Oct 12, 2012 at 12:04
In order to get the app working with my exported library .jar file, I had to copy everything in the resources directory "res" from the library project to the application project. Also had to merge file string.xml as well as merge the ApplicationManfiest.xml files as well. To add the project as a library through eclipse is much simpler.