android 对外部类的管理策略

来源:互联网 发布:知乎删除回答重新回答 编辑:程序博客网 时间:2024/05/16 05:38

Dependency resolution

When a project references two Library projects that both require the same jar file, the build system has to detect and resolve the duplication.

A full dependency system would associate each jar file with a fully qualified name and a version number to figure out which version to use.

Unfortunately the Android build system does not have a full dependency resolution system (yet). In the meantime we have implemented a very basic system that follows these rules:

Jar file are identified strictly by their file names.

This means mylib.jar is different than mylib-v2.jar and both will be packaged, possibly resulting in “already added” dx error if they are actually the same library in a different revision.

For jars with the same file name, “same version” means same exact file.

Currently our detection is very basic, checking only that the files are identical in size and sha1.
If two libraries each include in their libs folder a file called mylib.jar but these two files are different, then the build system will fail indicating a dependency error.

The solution is to make sure the two jar files are actually the same one if they are the same library or to rename them if they are different libraries.

Special case for android-support-v4.jar and android-support-v13.jar.

We make a special case for these two libraries because -v13 contains a full version of -v4 inside. If both are found, then only -v13 will be used.

Note that we can’t guarantee that the version of -v4 inside -v13 is the same as version used by the other libraries. We recommend that when you update your project with a newer version of the support library, you update all of your projects at the same time, whether they use -v4 or -v13.

原文链接:http://tools.android.com/recent/dealingwithdependenciesinandroidprojects