简体   繁体   English

如何在项目中独立共享资源文件夹?

[英]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.

相关问题 Java Maven 项目中,资源文件夹和目标文件夹如何映射? - In Java Maven project, how does resource folder and target folder map? 如何为mutli-project gradle项目实现全局资源文件夹? - How to implement a global resource folder for a mutli-project gradle project? 如何独立于Java项目的路径打开文件? - How to open a file independently of the path of the Java project? 如何从Java项目的resource / images文件夹加载图像? - how to load image from java project's resource/images folder? 在Java Gradle项目中设置资源文件夹 - Setting the Resource Folder in a Java Gradle project Netbeans Java 模块化项目 - 资源文件夹 - Netbeans Java Modular project - resource folder 在Project Explorer中以编程方式选择/扩展文件夹资源 - Programmatically selecting/expanding a folder resource in Project Explorer 如何在gwt maven项目中进行调试和修改时自动将webapp文件夹中的静态资源文件复制 - how to copy the static resource files in webapp folder automatically while debugging and on modification in a gwt maven project 在 Java Maven 项目中,如何使用 selenium 从资源文件夹上传文件(照片) - In Java Maven project how do I upload file (photo) from resource folder using selenium 如何从项目资源文件夹获取图像路径并发送到Java Eclipse中的另一个类 - How to get images path from project resource folder and send to another class in java eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM