WARNING [Project: :app] To shrink resources you must also enable ProGuard

新版本的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

时间: 2024-10-05 12:47:37

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

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 dependency的情形可能是:创建了两个Module,其中一个Module依赖另一个Module而导致了出现该问题: 如果在android Studio中,有ModuleA和ModuleB,我们希望ModuleA依赖ModuleB,运行时候可能会出现该问题,查看被依赖的ModuleB的build.

(转)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 dependency的情形可能是:创建了两个Module,其中一个Module依赖另一个Module而导致了出现该问题: 如果在Android Studio中,有ModuleA和ModuleB,我们希望ModuleA依赖ModuleB,运行时候可能会出现该问题,查看被依赖的ModuleB的build.

Task 'assembleXXXDebug' not found in project ':app'.的解决方法

如果项目构建时遇到了 Task 'assembleXXXDebug' not found in project ':app'.的问题,原因可能如下: 项目gradle配置文件里面设置了 productFlavors,比如改为了YYY,然后对应的debug的assemble应该是assembleYYYDebug,然而对应 Build Variants 可能还是 assembleXXXDebug,所以就会报这个错误. 解决方法就是在Android Studio右下角选择Build Variants,

The project references RTL attributes, but does not explicitly enable or disable RTL support 解决办法

If you do not support RTL (= Right To Left locales), you need to replace all references of start by left and end byright in your xml layouts. The attributes "start", "end", "paddingStart", "paddingEnd", "androi

[Android Studio] 取消引用库打包出现异常-- provided dependencies can only be jars

Warning: Project App: provided dependencies can only be jars. com.android.support:appcompat-v7:22.2.0 is an Android Library Warning: Project App: provided dependencies can only be jars. com.android.support:support-v4:22.2.0 is an Android Library. 以上是

Android项目代码混淆

项目根目录有两个文件: 1.project.properties # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant

构造Scala开发环境并创建ApiDemos示例项目

从2011年开始写Android ApiDemos 以来,Android的版本也更新了很多,目前的版本已经是4.04.ApiDemos中的例子也增加了不少,有必要更新Android ApiDemo示例解析系列文章(当然之前的文章还是有用的,依然可以作为参考).为了不重复之前的内容,我们准备使用Scala语言开发Android应用,随着例子的逐步解析,我们会把ApiDemos的例子的代码依次修改为Scala代码,并使用Robujuice 来注入View,关于Scala编程可以参考博客scala开发

spring4+srpingmvc+mybatis基本框架(app框架搭建一)

前言: 随着spring 越来越强大,用spring4来搭建框架也是很快速,问题是你是对spring了解有多深入.如果你是新手,那么在搭建的过程中可以遇到各种各样奇葩的问题. SSM框架的搭建是作为我搭建APP开发框架的基础. 我将会分以下几点: 1) 配置文件如何配置 2) 如何java配置启动servlet 3) 一些搭建过程中的坑 ============================================================================= 配置

Protecting resources in iPhone and iPad apps

源码:https://github.com/lingzhao/EncryptedResourceDemo UPDATE: The example project has been updated to work with iOS5. If you are distributing an iPhone or iPad app you may be giving away more than you realize. Resources that you embed in your applicat