Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Google recommend copying libraries into your tree?

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?

like image 710
poolie Avatar asked Oct 04 '22 00:10

poolie


1 Answers

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.

like image 50
GreyBeardedGeek Avatar answered Oct 13 '22 11:10

GreyBeardedGeek