4

I would like to use some xml files as mockups to preview different states of a layout, but I don't want to include it in the apk because thes xml files are only dedicated to preview purposes. I would like to tell gradle which files/directories to ignore for resources.

It would also be useful to easily reduce apk size for low memory devices by using products flavors, in a similar way as this excellent article explains.

Maybe proguard could help?

Louis CAD
  • 10,965
  • 2
  • 39
  • 58

2 Answers2

2

If you are using the android studio you can add resources by build flavors your want example you can add string resource for debug build only and different string resource for main release build. You just right click add a xml resource choose a resource type and specify the source set.

enter image description here

if you add a layout for debug flavor only and not in main release then everytime you sign an apk the those layout will not be included in apk. Hope it helps :)

Ariel Magbanua
  • 3,083
  • 7
  • 37
  • 48
  • Why I didn't think about that before! :) Thank you, it's not the way I thought I could solve this problem, but it's a working solution :) Also, if you are building worldwide apps, please, consider the link I provided in my question, I only have 8GB on my phone, it's a pain to choose which apps I'll have to uninstall to try another... – Louis CAD Aug 11 '15 at 10:14
  • @LouisCognault did I answered your question? What is really the problem you are facing? If I am right the proGuard will remove all unused classes. – Ariel Magbanua Aug 11 '15 at 10:17
  • 1
    Yes, you answered my question, it will just take a little time to configure these build flavors (and to move imported Material icons from plugin Android Drawable Importer, each time to flavors dirs one by one). – Louis CAD Aug 11 '15 at 10:28
  • I added my "mockups"to debug flavor, but got an error... `xmlns:android="http://schemas.android.com/apk/res/android"` is red marked by Android Studio, saying that Uri is not registered, and quick-fixes don't work... The problem is that it completely disables autocompletion, being a pain for long named resources. Did you have a similar misbehavior? – Louis CAD Aug 11 '15 at 12:58
1

We call it "Resource shrinking". All info about it is here.

Look at shrinkResources true. Build system will try to find unused resources files with this flag, and will remove them from the build. You can add it to your debug buildType, and on any build flavor.

android {
    ...

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Louis CAD
  • 10,965
  • 2
  • 39
  • 58