Why do Google recommend copying libraries into your tree?

牧云@^-^@ 提交于 2019-12-22 07:53:24

问题


Google's instructions for using the Play Service API (for example) say:

Copy the /extras/google/google_play_services/libproject/google-play-services_lib library project into the source tree where you maintain your Android app projects.

Note: You should be referencing a copy of the library that you copied to your source tree—you should not reference the library from the Android SDK directory.

This seems ugly to me - why not reference it from the SDK directory? Is there some technical reason for this? Or is it so that you have explicit control over when it gets upgraded?


回答1:


I'd like to point out that this is entirely a limitation of Eclipse, and it is indeed ugly.

The problem is that this library contains resources in addition to source code. Eclipse can only deal with libraries packaged as jar files, which, for the purposes of Android development, cannot contain resources.

So, in order for the library's resource to be compiled into the application, the library's source code, with the resources, must be added to your project.

If you move your build to Maven, and use an IDE that 'understands' Maven, then you can compile a library that contains resources as an 'apklib', and treat it as an external library, in a manner similar to a jar file.

The new Gradle-based build system is built on Maven primitives, but uses a different format for this, 'aar'. Hopefully, it will eventually also support apklib so that Maven builds and Gradle builds can inter-operate.

I just went through the exercise of converting an Android application to a Maven build, including the use of some apklibs. I can tell you that Eclipse with the m2eclipse plugin does not handle apklibs properly. Both IntelliJ and the new Google Android Studio (based on IntelliJ) do handle apklibs with no issues.




回答2:


It's not about "Play Services Library" specifically. Just like any other libraries that the project makes use of, this library should be referenced from project's source tree.

In this case the external library is in the Android SDK directory and referencing from there is not a good practice too. So yes, it can be called "a technical reason".

Used libraries (Play Services library in this case) shouldn't be referenced from anywhere other than the project's source tree.



来源:https://stackoverflow.com/questions/16781787/why-do-google-recommend-copying-libraries-into-your-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!