Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import **some** parts of guava library into Android app (gradle)

As any Android developer should know, there is a 65k method limit for your apk (because the VM has just 16 bits for method handling). It should be quite hard to reach by your own, but it's easy as soon as you start to add some libraries.

Since last year you can get rid of this by enabling MultiDex on Android 5.0 and above (and adding a support library for prior Android versions). Even when this is possible, it's always better to reduce the methods number and get a smaller api (and the performance should be better, shouldn't it?).

At certain point the Android guys realized the size of their Google Play Services library was unaffordable (20k methods) and they took the great decision of split it up in different modules, so you can add simply the parts you need like (with grade):

compile ('com.google.android.gms:play-services-analytics:8.1.0')
compile('com.google.android.gms:play-services-appindexing:8.1.0')

Do you know if is it possible to do something like that with Guava library? It's around 15K methods, so it will be really helpful. I would like to use just a small part of Guava, so I don't need/want to include the other. I've been looking in the documentation and googling, but nothing found.

compile group: 'com.google.guava', name: 'guava', version: '18.0'

Some guy asked something similar two years ago, probably for a Java project, but didn't exist smaller guava parts then. Downloading part of guava-libraries

The only thing that comes to my mind is to copy just the needed Guava classes instead of loading the library, but I think is an awful solution.

Don't you think any big library should use a module splitting system like they did with Play Services?

EDIT: Besides, the multidex task takes too long (one minute and a half when before was less than 15 seconds), so each time I want to launch the app I have to wait. So, even when using Proguard is a great solution for a production release, it's not suitable for development as it takes longer than multidexing.

like image 229
rolgalan Avatar asked Nov 13 '15 10:11

rolgalan


1 Answers

There is ongoing work to improve Guava on Android, but there are no plans to split it into smaller modules. As mentioned, ProGuard lets you exclude the parts of Guava you don't use from your final build.

like image 162
dimo414 Avatar answered Oct 11 '22 21:10

dimo414