简体   繁体   English

Android如何用资源导出jar?

[英]Android how to export jar with resources?

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! 我创建了一个用于构建我的自定义小部件的Android项目,我想将其导出为其他项目的jar,以便方便地重用它们,但现在问题是,我无法使用自定义小部件jar中包含的资源,例如一个png图片,它从类R的资源Id中获取一个空值! How can I sovle it? 我怎么能这样呢?

Update question: 更新问题:
How can I parse LayerDrawable xml from assets folder in code? 如何从代码中的assets文件夹解析LayerDrawable xml?

You cannot export self-contained Android Library jar at this time and announced will be available in the future SDK release. 您目前无法导出自包含的Android Library jar,并且将在未来的SDK版本中发布。
https://developer.android.com/guide/developing/projects/index.html#LibraryProjects https://developer.android.com/guide/developing/projects/index.html#LibraryProjects

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. 为了让应用程序使用我导出的库.jar文件,我必须将资源目录“res”中的所有内容从库项目复制到应用程序项目。 Also had to merge file string.xml as well as merge the ApplicationManfiest.xml files as well. 还必须合并文件string.xml以及合并ApplicationManfiest.xml文件。 To add the project as a library through eclipse is much simpler. 通过eclipse将项目添加为库更加简单。

You cannot export the Android Project to Jar with Resources. 您无法使用资源将Android项目导出到Jar。 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 请参阅文档此处显示如何将项目设置为库并在另一个项目中使用

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

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