在可分发的 Jar 文件中打包 Android 资源文件 [英] Packaging Android resource files within a distributable Jar file

查看:29
本文介绍了在可分发的 Jar 文件中打包 Android 资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些可重用的 Android 代码,我想将这些代码分发给其他开发人员,以便在他们自己的应用程序中使用.该代码具有一些资源依赖项(布局、xml 和 png 可绘制对象),我希望能够在单个包(Jar 文件)中包含和引用这些资源.

I am working on some reusable Android code that I would like to distribute to other developers for use within their own applications. The code has some resource dependencies (layouts, xml & png drawables) that I would like to be able to include and reference within a single package (Jar file).

这可能吗?如果可能,最好的方法是什么?

Is this possible, and if so what is the best method to do this?

推荐答案

我没有什么好消息要告诉你.通常,您无法像预期的那样轻松分发自己的软件包.主要问题是自动生成的 R 文件.您可能对它进行了一些参考 - 您有自己的布局和可绘制对象.您图书馆的用户将拥有他自己的 R 文件 - 包含他的资源的 ID,而不是您的图书馆提供的资源.

对于可绘制资源,您可以以经典方式读取它们,无需 R 文件.但据我所知,您无法从外部 xml 文件中扩展布局.

因此,这里的丑陋黑客是将您的库与您的所有资源一起分发,用户必须将其复制到他的res"文件夹中.老实说,您的问题没有好的解决方案......抱歉.问候!

I don't have any optimistic news for you. 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.

In case of drawable resources you could read them in classic way, without R file. But as far as I know you are not able to inflate layouts from external xml files.

So the ugly hack here would be to distribute your library together with all your resources, which user would have to copy to his "res" folder. To be honest, there is no good solution to your problem... sorry. Regards!

这篇关于在可分发的 Jar 文件中打包 Android 资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆