Den*_*ich 6 android proguard google-play-services build.gradle android-gradle-plugin
我正试图摆脱Google Play Services库中未使用的类.我用单个空活动创建了全新的android项目.该项目不使用Google Play Services库中的任何内容.所以我希望,当我构建版本(包括在我的配置中运行proguard)时,我会看到二进制大小与构建有/无play-services依赖关系没有区别.但实际上,我看到apk大小差异大约为700 KB .
我找到了相对复杂的解决方案,使用gradle脚本,其中涉及重新打包play-services.jar文件.此外,此解决方案需要明确指定不会使用的每个包.但我不明白为什么不在proguard我的案件中做这项工作?
的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'
}
Run Code Online (Sandbox Code Playgroud)
proguard-rules.pro:
-assumenosideeffects class android.util.Log {
public static *** d(...);
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
从Google Play Services 6.5及更高版本中,您可以选择要使用的API,并仅导入这些API.也许这会帮助你减少一点点的APK大小.这是一个清单:
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.+
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到更多相关信息.
| 归档时间: |
|
| 查看次数: |
4215 次 |
| 最近记录: |