Android how to export jar with resources?

2019-01-20 01:11发布

问题:

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?

回答1:

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



回答2:

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



回答3:

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.