使用 google-play-services_lib 添加 admob 广告后,Android 应用程序大小增加 [英] Android app size increased after adding admob ads using google-play-services_lib

查看:44
本文介绍了使用 google-play-services_lib 添加 admob 广告后,Android 应用程序大小增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算以两个版本发布我的应用,包括付费版和免费版(带有 AdMob 广告).
除了我在 AdMob 服务的免费版本中使用的 google-play-service_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.

使用 proguard 后的最终 apk 大小为:
付费版 1.301.435 字节
广告版本为 1.946.634 字节

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.

这是我与 google-play-service_lib 相关的 proguard 设置

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;
}

我可以做些什么来减少文件大小,比如删除一些 -keep 标志或什么?

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

编辑

使用 apktool 我发现 Google Play 服务包中没有任何类已缩小(包括 com.google.android.gms.maps.*com.google.android.gms.games.* 和许多其他我认为没有需要用于广告管理).

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?

编辑(再次)

看起来 Eclipse 没有保留 Proguard 的输出,至少我在任何地方都看不到它.然后我将我的项目和库配置为使用 Ant 构建以查看一些输出,但这几乎是不重要的,这是两种情况:

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.

(至少我读到该类没有被保留,尽管我可以使用 apktool 看到它!)和

(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.

我放弃了,对于一个插页式广告,我的应用程序的大小增加了 50%,尽管 Google 关于 GPS 声明:

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

如果您使用 ProGuard 作为一部分,客户端库的占用空间很小你的构建过程,所以它不会对你的应用的文件大小.

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!

推荐答案

和proguard无关.如您所知,google play 服务是封闭源代码.proguard 无源无法处理代码.但你可以手动缩小它.

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、从jar文件中删除未使用的类

1, remove unused class from jar file

在 google play 服务的文件夹中,通常是 sdkextrasgooglegoogle_play_serviceslibprojectgoogle-play-services_liblibs,用 7zip 等 zip 文件管理器打开 google-play-services.jar,你会发现很多如果您只使用广告,诸如地图,游戏等女巫的文件夹对您毫无用处.所以就删除它们.注意保留ads、common、dynamic、internallocation文件夹,否则在展示广告时会收到 NoClassDefFoundError 的 fc.

in the folder of google play service, typically sdkextrasgooglegoogle_play_services libprojectgoogle-play-services_liblibs, 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,如果您只使用广告,请从 res 文件夹中删除未使用的资源.

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

google-play-services_lib es 文件夹中的许多资源对您没有用处,您可以将其删除.比如 values-af, values-am, .... 你需要保留的是 color, drawable, drawable-hdpivalues 文件夹.

many resource in google-play-services_lib es 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,现在刷新并在你的 Eclipse 中构建 google-play-services_lib 项目,然后刷新并再次构建您的项目.现在你会发现 apk 的大小变小了.我的大小apk在proguard之前从902kb下降到480kb,在proguard之后下降到330kb.

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.

这篇关于使用 google-play-services_lib 添加 admob 广告后,Android 应用程序大小增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆