包装内分发的JAR文件的Andr​​oid资源文件文件、资源、JAR、oid

2023-09-12 03:48:07 作者:About_美ゝ

我工作的一些可重复使用的Andr​​oid code,我想发给其他开发人员为自己的应用程序中使用。在code具有一定的资源依赖关系(布局,XML和放大器;巴可绘制),我希望能有和在单个封装内引用(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档 - 包含IDS对他的资源,而不是那些你的库提供。

如果是绘制资源,你可以阅读他们经典的方式,没有R档。但据我所知,你是不是能够从膨胀外部XML文件中的布局。

因此​​,这里的丑陋的黑客会用所有的资源,用户必须复制到自己的资源文件夹一起分发库中。说实话,也没有很好的解决你的问题...对不起。 商祺!

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!