Android Eclipse 库项目和项目特定配置文件的库项目类型解析

发布于 2024-12-07 06:49:07 字数 1146 浏览 1 评论 0原文

我有几个 Android 项目共享我的库项目之一。我想让库代码依赖于某些配置类,这些配置类在依赖它的项目中定义不同。为了使非 lib 项目在 Eclipse 项目资源管理器中不报告错误,这意味着在每个项目中提供具有相同完全限定路径的类定义。

所以结构看起来像这样

Tablet_Project:

defines com.mycompany.config.ClientPrefs.java

Phone_Project:

defines com .mycompany.config.ClientPrefs.java

Lib_Project:

依赖但不定义 com.mycompany.config.ClientPrefs.java

一旦完成此操作,项目在 Eclipse 项目资源管理器中没有显示任何错误,但该库有一个红色的“X”,表明它可以解析 ClientPrefs 引用 - 这是我所期望的,因为无论如何你都无法编译库,所以看起来没什么大不了的。

问题:手机项目编译并运行良好,但平板电脑项目报告在启动之前需要修复错误,即使其工作区资源管理器中的任何位置都没有“X”指示符。

问题:这种配置方法实际上在这些项目中是允许的,还是电话项目的运行只是一个意外?

编辑 这是我能想到的最基本的例子: 在此处输入图像描述

ProjectA 和 ProjectB 依赖于 ProjectLib 作为 Android 库项目。如此处所示,ProjectLib 的 Util.java 无法解析对 Config.java 缺少的引用,但这对于 A 和 B 来说似乎并不重要,因为它们似乎为 ProjectLib 解决了这个问题,从而构建和运行。还有其他人采用这种方法进行配置吗?

我问的原因是因为我有一组更大的项目,其中一个项目将不再构建(在 Eclipse 中),大概是因为它的 lib 项目有错误。从命令行使用 Ant 构建总是有效,这让我认为库项目会被拉入依赖项目,而不考虑它的 Eclipse 边界。

I've got several android projects that share one of my library projects. I want to have the library code depend on certain configuration classes that are defined differently in the project(s) that are depending on it. In order to get the non-lib projects to report no errors in Eclipse project explorer, this means providing class definitions in each project with the same fully-qualified path.

So the structure looks like this

Tablet_Project:

defines com.mycompany.config.ClientPrefs.java

Phone_Project:

defines com.mycompany.config.ClientPrefs.java

Lib_Project:

depends on but does not define com.mycompany.config.ClientPrefs.java

Once this done, the projects show no errors in Eclipse project explorer, but the lib has a red "X" indicating that it can resolve the ClientPrefs reference - which I would expect, Since you can't compile a lib anyway it doesn't seem like a big deal.

Problem: The phone project compiles and runs fine, but the tablet project reports that an error needs to be fixed before launching even though there are no "X" indicators anywhere in its workspace explorer.

Question: Is this approach to configuration actually permissible in these projects or is the fact that the phone project works just an accident?

Edit
Here is the most basic example I can come up with:
enter image description here

ProjectA and ProjectB depend on ProjectLib as an Android Library project. As displayed here, ProjectLib's Util.java can't resolve the missing ref to Config.java but this doesn't seem to matter for A and B since they seem to resolve this for ProjectLib and thus both build and run. Anyone else taken this approach to config?

The reason I ask is because I have a much larger set of projects, and one of them won't build anymore (in Eclipse) presumably since it's lib project has errors. Building with Ant from the command line always works and that makes me think that a library project gets pulled into the dependent project without regard to it's Eclipse boundary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-12-14 06:49:07

之前可以在 ProjectA 和 ProjectB 中创建相同的 Config 类,并从 lib 项目中排除 Config 类。

但是现在库项目被包含为jar,并且无法在eclipse中从jar中排除类。

我的临时解决方案是使用 config util 类,它返回正确的配置,每次构建不同的项目时我都需要更改它。

public class Config {

    private static MyConfig config;

    public static MyConfig getConfig() {
        if (config == null) {
            config = new MyConfig();
        }
        return config;
    }
// ...
// CONSTANTS 
// ...
}

Before it was possible to make the same Config class in the ProjectA and ProjectB, and exclude the Config class from lib project.

But now the library project is included as jar, and it is not possible to exclude class from jar in eclipse.

My temporary solution to have config util class, which returns the correct Config, I need to change it each time when build different project.

public class Config {

    private static MyConfig config;

    public static MyConfig getConfig() {
        if (config == null) {
            config = new MyConfig();
        }
        return config;
    }
// ...
// CONSTANTS 
// ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文