[英]How to share resource folder independently in project?
I have a library project, it contains all resources and class files, this project contains all theme related images, I am sharing my library project for creating new Projects, all works fine. 我有一个图书馆项目,它包含所有资源和类文件,该项目包含所有与主题相关的图像,我正在共享我的图书馆项目以创建新的Projects,所有工作都很好。
But when I want to change app theme related images, I need to update my library project images, but my library project already shared with some other projects so I don't want to touch it. 但是,当我想更改与应用程序主题相关的图像时,我需要更新我的图书馆项目图像,但是我的图书馆项目已经与其他一些项目共享,所以我不想碰它。
There is one more way that I can add all new set of image in my New project but its increasing my project size and unnecessary I am shipping two sets on images. 我可以通过另一种方式在“新项目”中添加所有新图像集,但是这会增加项目大小,并且不必要在图像上运送两套图像。
Is there any way to share resource folder independently with project? 有什么方法可以与项目独立共享资源文件夹吗? so depends on requirement I can share my resource folder with respected project. 因此,根据要求,我可以与受尊重的项目共享我的资源文件夹。
So it will be like this 所以会像这样
Library Project | |__ class files | |__ resource folder(contais all drawables and layouts)
Can I choose a specific resource folder at compile time ? 我可以在编译时选择一个特定的资源文件夹吗?
I would version the library and manage dependencies with maven or something similar. 我会对该库进行版本控制,并使用Maven或类似方法管理依赖项。 This way, you don't break the rest of the projects that are using old versions of the libraries, you can update any project to any version of the library when you have time, and of course, you can keep updating the library and generating new versions. 这样,您就不会破坏正在使用旧版本库的其余项目,可以在有时间的时候将任何项目更新到库的任何版本,当然,您可以继续更新库并生成新版本。
I would add a static
field describing the resources folder in the library which goes like this. 我将在库中添加一个static
字段来描述资源文件夹,如下所示。
public class Library {
// The resource-folder
public static final File RES_FOLDER;
}
Then use the field to access the resource folder. 然后使用该字段访问资源文件夹。 And I recommend creating themes as separate apps. 我建议将主题创建为单独的应用。
Solution #1: Versioned resources, downloaded in runtime from the web. 解决方案#1:版本化的资源,可在运行时从Web下载。 Consider to not embed any resources into your library project. 考虑不要将任何资源嵌入到您的库项目中。 This way you will be able to distribute it as .jar file, that will simplify integration for 3-rd party developers. 这样,您就可以将其分发为.jar文件,从而简化了第三方开发人员的集成。 This way you will need to download resources in runtime from the web and cache them in /data folder or on SD card or in memory. 这样,您将需要在运行时从Web下载资源,并将其缓存在/ data文件夹或SD卡或内存中。
Solution #2: Use ant or maven to build your project. 解决方案2:使用ant或maven构建项目。 This way you will be able to distribute your project with default configuration and with the possibility to build custom configuration. 这样,您将可以使用默认配置分发项目,并可以构建自定义配置。 This way resources can be located in any folder and will be taken from there during compilation, according to defined configuration parameter. 这样,根据定义的配置参数,资源可以位于任何文件夹中,并且在编译过程中将从那里获取资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.