How to exclude res folder from gradle build flavours?

后端 未结 2 734
深忆病人
深忆病人 2020-12-03 17:24

I have a requirement to remove a specific res folder from a flavour.

sourceSets {
    main {
        manifest.srcFile \'AndroidManifest.xml\'
        java.sr         


        
2条回答
  •  借酒劲吻你
    2020-12-03 18:20

    I finally solved this problem!

    I have found this link.

    And did this:

    1. add an xml file to res/raw folder. I named it resources_discard.xml, here is it:

      
      
      
    2. this file is placed in the correct directory structure for my flavor called lite ("src/lite/res/raw")

    This way, contents of res/hd folder are not included in lite builds, effectively reducing my lite build apk size by 50%

    Update: to exclude some images from different flavors, you have to put the images in the "assets" folder, and in gradle declare:

        flavor {
            aaptOptions {
                ignoreAssetsPattern '/folder:*.jpg:*.png' //use : as delimiter 
            }
        }
    

    I also learned that you can't have subfolders in /res/raw folder.

提交回复
热议问题