开发者

Android Eclipse library project and the library project's type resolution for project specific config files

开发者 https://www.devze.com 2023-04-09 16:10 出处:网络
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 ar

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 开发者_如何学Cto 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:

Android Eclipse library project and the library project's type resolution for project specific config files

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.


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 
// ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消