使用Proguard的去除在谷歌未使用类游戏服务库 [英] Using Proguard to remove unused classes in Google Play Services library
问题描述
我想从摆脱未使用的类谷歌播放服务
库。我已经创建了一个空的活动品牌新的Android项目。该项目的不使用从什么谷歌播放服务
库。所以,我希望,当我建立的释放(包括在我的配置中运行ProGuard的)我会看不在比较建筑/二进制大小没有区别玩-服务
的依赖。但实际上,我看到 APK
尺寸〜700 KB的差异。
我发现相对复杂的解决方案,使用摇篮脚本,其中涉及重新打包播放services.jar文件。此外,这种解决方案需要明确地指定每个包哪个是不会被使用。但我不明白为什么不 ProGuard的
做好这项工作在我的情况?
build.gradle:
应用插件:com.android.application
安卓{
compileSdkVersion 21
buildToolsVersion21.1.1
defaultConfig {
的minSdkVersion 10
targetSdkVersion 21
}
buildTypes {
推出 {
minifyEnabled真
proguardFiles getDefaultProguardFile('ProGuard的-的Android optimize.txt'),'proguard-rules.pro
}
}
}
依赖{
//!当我评论了线下方,发布APK是700 KB的! //
编译com.google.android.gms:播放服务:87年6月5日
}
proguard-rules.pro:
-assumenosideeffects类android.util.Log {
公共静态*** D(...);
}
的AndroidManifest.xml:
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.test.noplayservices>
<应用的Android版本:allowBackup =真
机器人:标签=@字符串/ APP_NAME
机器人:图标=@可绘制/ ic_launcher
机器人:主题=@风格/ AppTheme>
<活动机器人:ui.activities.MainActivity名称=机器人:图标=@可绘制/ ic_launcher>
<意向滤光器>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
MainActivity.java:
包com.test.noplayservices.ui.activities;
进口android.app.Activity;
进口android.os.Bundle;
进口com.test.noplayservices.R;
公共类MainActivity延伸活动{
@覆盖
公共无效的onCreate(包savedInstance){
super.onCreate(savedInstance);
的setContentView(R.layout.main_activity);
}
}
从谷歌播放服务6.5版本及以后你可以选择你要使用的各个API和进口只是那些的。也许这会帮助你减少APK大小一点点。这里有一个列表:
的Google+ com.google.android.gms:玩-服务加:6.5 +
谷歌帐户登录com.google.android.gms:玩-服务身份:6.5 +
谷歌行为识别com.google.android.gms:播放服务地点:6.5 +
谷歌应用程序索引com.google.android.gms:播放服务-appindexing:6.5 +
谷歌演员com.google.android.gms:播放服务铸:6.5 +
谷歌驱动器com.google.android.gms:播放服务驱动:6.5 +
谷歌飞度com.google.android.gms:播放服务,健身:6.5 +
谷歌地图com.google.android.gms:播放服务-图:6.5 +
谷歌移动广告com.google.android.gms:播放服务,广告:6.5 +
谷歌全景图查看器com.google.android.gms:玩-服务全景:6.5 +
谷歌玩游戏服务com.google.android.gms:玩-服务游戏:6.5 +
谷歌钱包com.google.android.gms:播放服务钱包:6.5 +
Android Wear com.google.android.gms:播放服务耐磨:6.5 +
谷歌的行动
谷歌分析
谷歌云消息传递com.google.android.gms:玩-服务基地:6.5 +
您可以看到更多关于这这里。
I'm trying to get rid of unused classes from Google Play Services
library. I've created brand new android project with single empty activity. The project does not use anything from Google Play Services
library. So I would expect, that when I build release (which includes running proguard in my configuration) I will see no difference in binary size comparing building with/without play-services
dependency. But actually, I see ~700 KB difference in apk
size.
I've found relatively complex solution, using gradle script, which involves repacking play-services.jar file. Also, this solution requires to specify explicitly each package which is not going to be used. But I don't understand why doesn't proguard
do this work in my case?
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// !!! when I comment the line below, release APK is 700 KB smaller !!! //
compile 'com.google.android.gms:play-services:6.5.87'
}
proguard-rules.pro:
-assumenosideeffects class android.util.Log {
public static *** d(...);
}
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.noplayservices">
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<activity android:name=".ui.activities.MainActivity" android:icon="@drawable/ic_launcher">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
package com.test.noplayservices.ui.activities;
import android.app.Activity;
import android.os.Bundle;
import com.test.noplayservices.R;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
setContentView(R.layout.main_activity);
}
}
From Google Play Services version 6.5 and beyond you can select which individual APIs you want to use, and import just those ones. Maybe that will help you decrease the APK size a little bit. Here's a list:
Google+ com.google.android.gms:play-services-plus:6.5.+
Google Account Login com.google.android.gms:play-services-identity:6.5.+
Google Activity Recognition com.google.android.gms:play-services-location:6.5.+
Google App Indexing com.google.android.gms:play-services-appindexing:6.5.+
Google Cast com.google.android.gms:play-services-cast:6.5.+
Google Drive com.google.android.gms:play-services-drive:6.5.+
Google Fit com.google.android.gms:play-services-fitness:6.5.+
Google Maps com.google.android.gms:play-services-maps:6.5.+
Google Mobile Ads com.google.android.gms:play-services-ads:6.5.+
Google Panorama Viewer com.google.android.gms:play-services-panorama:6.5.+
Google Play Game services com.google.android.gms:play-services-games:6.5.+
Google Wallet com.google.android.gms:play-services-wallet:6.5.+
Android Wear com.google.android.gms:play-services-wearable:6.5.+
Google Actions
Google Analytics
Google Cloud Messaging com.google.android.gms:play-services-base:6.5.+
You can see more about this here.
这篇关于使用Proguard的去除在谷歌未使用类游戏服务库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!