新版本的Android Gradle plugin中,对于resource有了更加一步的管理,可以把unused resource移除,不仅是自己工程,并且library里面也可以没有用到的,也可以移除。

需要体验这个功能,build.gradle配置如下:

android {
... buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

  

为了使用shrinkResources,必须先开启minifyEnabled,依赖关系。

当你配置完毕,运行查看日志

...
:android:shrinkDebugResources
Removed unused resources: Binary resource data reduced from 2570KB to 1711KB: Removed 33%
Note: If necessary, you can disable resource shrinking by adding
android {
buildTypes {
debug {
shrinkResources false
}
}
}
:android:validateDebugSigning
...

  

如果需要查看更详细的具体哪些resource被移除了,可以在Gradle command输入一下命令:--info

$ ./gradlew clean assembleDebug --info | grep "Skipped unused resource"
Skipped unused resource res/anim/abc_fade_in.xml: 396 bytes
Skipped unused resource res/anim/abc_fade_out.xml: 396 bytes
Skipped unused resource res/anim/abc_slide_in_bottom.xml: 400 bytes
Skipped unused resource res/anim/abc_slide_in_top.xml: 400 bytes
Skipped unused resource res/anim/abc_slide_out_bottom.xml: 400 bytes
Skipped unused resource res/anim/abc_slide_out_top.xml: 400 bytes
Skipped unused resource res/color/rating_bar_label.xml: 472 bytes
Skipped unused resource res/drawable-xhdpi-v4/big.png: 866901 bytes
Skipped unused resource res/drawable-xhdpi-v4/ic_action_add_schedule.png: 282 bytes
Skipped unused resource res/drawable-xhdpi-v4/ic_action_remove_schedule.png: 368 bytes
Skipped unused resource res/drawable-xhdpi-v4/ic_livestream_pause.png: 1694 bytes
Skipped unused resource res/drawable-xhdpi-v4/ic_livestream_play.png: 2141 bytes
Skipped unused resource res/drawable-xhdpi-v4/ic_media_route_on_holo_light.png: 1594 bytes
Skipped unused resource res/drawable-xxhdpi-v4/actionbar_icon.png: 2002 bytes
Skipped unused resource res/drawable-xxhdpi-v4/ic_action_overflow.png: 330 bytes
Skipped unused resource res/drawable-xxhdpi-v4/ic_action_play_dark.png: 331 bytes
Skipped unused resource res/drawable/photo_banner_scrim.xml: 620 bytes
Skipped unused resource res/drawable/session_detail_photo_gradient.xml: 620 bytes
Skipped unused resource res/drawable/transparent_background_pattern.xml: 436 bytes
Skipped unused resource res/layout/activity_letterboxed_when_large.xml: 360 bytes
Skipped unused resource res/menu/sessions_context.xml: 1088 bytes
Skipped unused resource res/raw/keep.xml: 262 bytes
Skipped unused resource res/transition-v21/shared_element.xml: 1008 bytes
Skipped unused resource res/transition-v21/window_enter_exit.xml: 108 bytes

  

from:http://tools.android.com/tech-docs/new-build-system/resource-shrinking

WARNING [Project: :app] To shrink resources you must also enable ProGuard的更多相关文章

  1. Android Studio解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  2. Android Studio添加应用作为依赖时报错Error:Dependency MonthText:xlistview:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: 及其解决方案

    Error:Dependency MonthText:xlistview:unspecified on project app resolves to an APK archive which is ...

  3. Error:The SDK Build Tools revision (19.0.3) is too low for project ':app'. Minimum required is 19.1.

    今天更新了一下AndroidStudio, 结果编译程序时报错, 错误如下: Error:The SDK Build Tools revision (19.0.3) is too low for pr ...

  4. Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app

    出现的问题: Error:Execution failed for task ':app:preDebugAndroidTestBuild'.> Conflict with dependency ...

  5. Android Studio 解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  6. Andrid Studio Gradle sync failed: A problem occurred configuring project ':app' 解决方法

    Android Studio中进行Gradle sync 时出现了这个错误,Android Studio 出错提示是 Gradle sync failed: A problem occurred co ...

  7. (转)Android Studio解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  8. django基础PROJECT APP View template

    project 和 app 的区别就是一个是配置另一个是代码: 一个project包含很多个Django app以及对它们的配置. 一个project的作用是提供配置文件,比方说哪里定义数据库连接信息 ...

  9. Visual Studio 2013 Unit Test Project App.config文件设置方法

    开放中经常会要做单元测试,新的项目又没有单元测试项目,怎么才能搭建一个单元测试项目呢? 下面跟我四步走,如有错误之处,还请指正! 1.添加项目 2.添加配置文件 新建app.config文件,注意不是 ...

随机推荐

  1. 【转载】Xcode6中添加pch文件

    //原文地址:http://www.cnblogs.com/YouXianMing/p/3989155.html 1. 新建工程: 2. 创建pch文件:cmd+n->other->PCH ...

  2. Floyd算法(弗洛伊德算法)

    算法描述: Floyd算法又称为弗洛伊德算法,插点法,是一种用于寻找给定的加权图中顶点间最短路径的算法.从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按 ...

  3. C#的一个异常

    1.catch捕获得到的异常如图 2.解决办法(找到app.config文件,修改图中的值将原来的8192扩大了10倍)

  4. golang make the first character in a string lowercase/uppercase

    import ( "unicode" ) func UcFirst(str string) string { for i, v := range str { return stri ...

  5. linux shell--算术运算

    求和: 方法一.使用命令替换法: #!/bin/bash read -p 'input number a...' numA read -p 'input number b...' numB #这里有两 ...

  6. 混合使用Azure LB和ILB访问相同web服务(2)

    那么现在开始,我们配置下两台WEB服务器的Internal Load  balancer: 打开Powershell,检查当前两台虚拟机的端点配置: Get-AzureVM  -ServiceName ...

  7. ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小 错误分析

    目录(?)[+] 1. 问题起因 最近在进行Oracle的一些操作时,总会遇到这个错误:  ORA-06502: PL/SQL: 数字或值错误 :  字符串缓冲区太小,错误如下: ORA-00604: ...

  8. QT多重继承的时候,要把QObject放在最前面,否则报错——C++认为人性本恶,默认都是私有的,这点和Delphi的世界观不一样

    在买来的控件(没有源码)的基础上,想加入QObject的一些特性,不得不多继承: class MyProgress : public CProgress, public QObject 但总是报错: ...

  9. centos curl web站点监控实践

    1,监控给定web站点的状态--站点请求返回代码,下载整个web站点页面文本到-o 指定的文本 curl -o /dev/null -s-silent -w--wirte-out "%{ht ...

  10. 【男性身材计算】胸围=身高*0.48(如:身高175cm的标准胸围=175cm*0.61=84cm);腰围=身高*0.47(如:身高175c… - 李峥 - 价值中国网

    [男性身材计算]胸围=身高*0.48(如:身高175cm的标准胸围=175cm*0.61=84cm):腰围=身高*0.47(如:身高175c- - 李峥 - 价值中国网 李峥:[男性身材计算]胸围=身 ...