Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app size increased after adding admob ads using google-play-services_lib

I'm gonna publishing my app in two versions, both paid and free (with AdMob ads).
The two versions are exactly identical except for the google-play-service_lib that i use in the free version for AdMob services.

The final apk sizes after using proguard are:
1.301.435 bytes for paid version
1.946.634 bytes for ads version

In free version i show interstitial ads only.

Here's my proguard settings relative to the google-play-service_lib

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

Is there something i can do to reduce file size like removing some -keep flags or what?

EDIT

Using apktool i discovered that none of the classes from the Google Play Service package has been shrinked (including com.google.android.gms.maps.*, com.google.android.gms.games.* and many others that i think are not needed for Ads management).

How to force shrink a class or a class group?

EDIT (again)

It looks like Eclipse doesn't keep Proguard output, at least i couldn't see it anywhere. I then configured my projects and libs to be build using Ant to see some output, but it's almost unsubstantial, these are two cases:

 -whyareyoukeeping class com.google.android.gms.maps.GoogleMap

 [proguard] Explaining why classes and class members are being kept...
 [proguard] Printing usage to [...../bin/proguard/usage.txt]...
 [proguard] com.google.android.gms.maps.GoogleMap
 [proguard]   is not being kept.

(at least i read that class is not been kept, although i can see it using apktool!) and

 -whyareyoukeeping class com.google.android.gms.games.Games

 [proguard] Explaining why classes and class members are being kept...
 [proguard] Printing usage to [...../bin/proguard/usage.txt]...

here nothing is said about given class.

I'm giving up, for a single interstitial my app increases his size by 50%, although Google about GPS states:

The client library has a light footprint if you use ProGuard as part of your build process, so it won't have an adverse impact on your app's file size.

and no-where i could find a guide for it!

like image 972
j.c Avatar asked Feb 04 '14 14:02

j.c


People also ask

Can I use AdMob without uploading at Play Store?

Save this answer. Show activity on this post. You can definitely use Admob without uploading your app to Google Play. The question is why wouldn't you upload your app to Google Play - it is a very large market that you will be missing out on.

Does AdMob take a cut?

No, using AdMob is free.

What is the difference between Google ads and AdMob?

Google Ads makes it possible for you to promote your product info within specific apps, i.e. display ads for your website specifically in mobile apps, while Admob only allows you to advertise your app within other apps. AdMob helps you earn revenues by having other ads that show within your app on the mobile.

How much do AdMob pay for interstitial ads?

Interstitial advertising The average eCPM for interstitial ads range from $4-$6. Ever heard of rewarded interstitial ads? Serve your users an interstitial ad and then reward them with in-game currency. Rewarded interstitials are a great way to improve your user's ad experience.


2 Answers

it is nothing to do with proguard. as you know, google play service is close source. proguard can't handle it without source code. but you can shrink it manually.

1, remove unused class from jar file

in the folder of google play service, typically sdk\extras\google\google_play_services \libproject\google-play-services_lib\libs\, open google-play-services.jar with zip file manager such as 7zip, you can find many folder such as maps, games and so on witch is no use for you if you only use ads. so just delete them. be careful to keep ads, common, dynamic, internal and location folder otherwise you will get fc of NoClassDefFoundError when show ads.

2, remove unused resource from res folder if you only use ads.

many resource in google-play-services_lib\res folder is no use for you, you can remove it. such as values-af, values-am, .... what you need to keep is color, drawable, drawable-hdpi and values folder.

3, now refresh and build the google-play-services_lib project in your eclipse, then refresh and build your project again. now you shold find the apk size get smaller. the size of my apk go down from 902kb to 480kb before proguard, and 330kb after proguard.

like image 65
daniel Avatar answered Oct 05 '22 21:10

daniel


did u use this line in your build.gradle file?

compile 'com.google.android.gms:play-services:6.+'

if yes then supplement it with this line

compile 'com.google.android.gms:play-services-ads:6.+'

It reduces the app size by around 600kb.

like image 25
Devenom Avatar answered Oct 05 '22 21:10

Devenom