Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize Google play services to decrease jar size?

I wonder if there is a way to customize google-play-services.jar.

Google play services version 6.1

I found that new version has 24K methods that makes my application out of Max method count (~65K) and therefore I can't create APK file (or DEX).

In the past I saw on some site that you can configure google-play-services.jar by enable/disable unused features.

My old jar weight is 7K (instead 19K) and I can't jump to 24K, too expansive.

Any suggestions please?

[EDIT]

I found this question where @Eric Lafortune suggests to use Proguard

like image 529
snaggs Avatar asked Oct 22 '14 11:10

snaggs


People also ask

Is Google Play services essential?

Google Play services helps to ensure the security and reliability of an Android device, and keep devices updated with the latest security features. This includes: Google Play Protect, which can warn users if an app contains known malware.

What data does Google Play services keep?

Google Play services offers APIs to other apps. Data used by Play services is mostly cached data for these APIs, duplicated data of Android wear apps synched with your phone and some kind of search index.


3 Answers

Ideally you should use ProGurad, however you can follow these two steps:

Step 1: Remove unused classes from jar file

Open the google-play-services.jar in the library project with a zip file manager such as Winrar or 7zip. You will find many folder such as maps, games, just delete the ones you don't need. Make sure you keep common, dynamic, internal .

Step 2: Remove unused resource from res folder

Most of the resources in the google-play-services_lib\res folder might be of no use so you can remove it. These include values-af, values-am, .... what you need to keep is color, drawable, drawable-hdpi and values folder.

Refresh and build the google-play-services_lib project and your project. Your apk size should be decreased.

like image 184
Nana Ghartey Avatar answered Oct 05 '22 02:10

Nana Ghartey


In Android Studio You can use individual library from google play service such as

compile 'com.google.android.gms:play-services:7.5.0'

with these lines:

compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'

complete list is available here https://developers.google.com/android/guides/setup

Some APIs do not have a separate library; include them by including the base library

like image 25
Dharmaraj Avatar answered Oct 05 '22 01:10

Dharmaraj


Keeping in mind that:

  • Using Proguard is always recommended
  • MultiDex, despite adding overhead at runtime, is the only viable solution when you are really using all of those methods (which is rarely the case!)

If you are using Gradle and just want to exclude automatically the parts of Play Services that you don't use, this is the easiest, fastest, and most efficient way: https://gist.github.com/Takhion/10a37046b9e6d259bb31.

Just add it as suggested and comment the exclude on the parts that you need!

Sooo useful for debug builds where you don't want to go through Proguard each time ;)

like image 28
Takhion Avatar answered Oct 05 '22 01:10

Takhion