收缩谷歌播放服务库,只有谷歌Analytics(分析)使用 [英] Shrink Google Play Services library for use with Google Analytics only

查看:172
本文介绍了收缩谷歌播放服务库,只有谷歌Analytics(分析)使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从谷歌播放服务库中删除不必要的软件包,该库将只包含所需的谷歌Analytics(分析)的一切吗?

Is it possible to remove unnecessary packages from the Google Play Services library so that the library will only contain everything needed for Google Analytics?

我问这是因为谷歌播放服务库是臃肿,而我认为是未使用谷歌分析额外的软件包,图片和资源。

I'm asking this because the Google Play Services library is bloated with extra packages, images and resources of which I think are unused by Google Analytics.

推荐答案

Proguard的删除未使用$ C $从jar文件默认情况下,C也从谷歌播放服务库。但ProGuard的不能被用于去除(未使用)的资源,但我发现,还有其他选项,进一步优化库。

Proguard removes unused code from jar files by default also from the Google Play Services library. But proguard cant be used to remove (unused) resources, but I have found that there are other options to further optimize the library.

我可以使用方法二缩水从 1827 KB 一个应用程序到 1115 KB 。我测试的应用程序,并能正常工作和谷歌Analytics(分析)静是出现在如预期的在线仪表板。

I was able using method two to shrink an app from 1827 KB down to 1115 KB. I tested the app and it works fine and Google Analytics statics are appearing on the online dashboard as expected.

第一种方法可能是最容易的。

The first method is probably the most easy.

第1步:从库项目的谷歌播放-services.jar文件复制到自己的项目和以往它在libs文件夹

Step 1: Copy the google-play-services.jar file from the library project to your own project and past it in the libs folder.

第二步:从项目中删除库引用到原来的谷歌播放的,services_lib项目

Step 2: Remove the library reference to the original google-play-services_lib project from your project.

Right click on your project -> Properties -> Android -> Select library -> Remove

第三步:添加dontwarn标志的progruard设置文件

Step 3: Add dontwarn flags to your progruard settings file.

-dontwarn com.google.**.R
-dontwarn com.google.**.R$*

说明:在谷歌播放-服务-JAR中包含对生成的Java文件(R.java)。通常,当谷歌播放-services_lib项目正在构建生成这些文件。 Proguard的,通常会提醒你(通过一个错误退出),这些文件优化谷歌播放-services.jar文件时丢失。通过添加dontwarn标志的ProGuard会忽略一个事实,即这些文件丢失,不会出错退出。

Explanation: The google-play-services-jar contains references to generated Java files (R.java). These files are normally generated when the google-play-services_lib project is being build. Proguard will normally warn you (By exiting with an error) that these files are missing when optimizing the google-play-services.jar file. By adding the dontwarn flags proguard will just ignore the fact that these files are missing and won't exit with an error.

方法二是方法之一更优化的版本。所不同的是,而不是从图书馆项目中的谷歌播放-services.jar文件复制到自己的项目,你首先使用ProGuard的优化库。

Method two is an more optimized version of method one. The difference is that instead of copying the google-play-services.jar file from the library project to your own project you first optimize the library using proguard.

所以,你想要做的是手动上只是谷歌的播放,services.jar文件运行ProGuard的。为了保持只是谷歌Analytics(分析)我用这个ProGuard的设置文件。

So what you want to do is manually run proguard on just the google-play-services.jar file. For keeping just Google Analytics I used this proguard settings file.

-injars google-play-services.jar
-outjars google-play-services-analytics.jar

-libraryjars [add your path to sdk]/sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars [add your path to sdk]/sdk/platforms/android-21/android.jar

-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote

-keep public class com.google.android.gms.analytics.**, com.google.android.gms.common.**, com.google.android.gms.location.** {
    public protected *;
}

-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    java.lang.String NULL;
}

第1步:从库项目中复制谷歌的播放,services.jar文件的 SDK \工具\ ProGuard的\ LIB 文件夹

Step 1: Copy the google-play-services.jar file from the library project to the sdk\tools\proguard\lib folder.

第二步:复制您的ProGuard的设置文件的 SDK \工具\ ProGuard的\ LIB 文件夹

Step 2: Copy your proguard settings file to the sdk\tools\proguard\lib folder.

第三步:运行progaurd您的设置文件:

Step 3: Run progaurd with your settings file:

在Windows上:打开命令窗口 - >导航到 SDK \工具\ ProGuard的\ LIB 文件夹 - >使用运行ProGuard的:

On windows: Open command window -> Navigate to the sdk\tools\proguard\lib folder -> Run proguard using:

java -jar proguard.jar @analytics-settings.txt

第四步::使用第一种方法在这篇文章中解释,优化谷歌,播放服务,analytics.jar添加到您的项目。 (不要忘记在第一种方法步骤3!)

Step 4: Use the first method explained in this post to add the optimized google-play-services-analytics.jar to your project. (Don't forget Step 3 in the first method!)

Before + proguard = 1827 KB
Method 1 = 1206 KB
Method 2 = 1115 KB

这篇关于收缩谷歌播放服务库,只有谷歌Analytics(分析)使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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