1

This is an Android project. I tried to exclude a resource file under assets folder. I tried

"aaptOptions {ignoreAssetsPattern "file.json"}"

But it excludes the file for all build variants.

I tried the following, but it still did not work.

android.variantFilter { variant -> if (variant.buildType.name.equals('release')) { variant.mergeAssets.doLast { delete(fileTree(dir: 'assets/filedir', includes: ['file.json'])) } } }

Please help. Thanks a lot.

KKONG
  • 11
  • 3

1 Answers1

-1

You can check if you are in release or debug mode by querying the BuildConfig object. By doing this you can set a conditional verification and exclude the file you want to get rid of for a specific BuildConfig mode:

if (BuildConfig.RELEASE) 
{
    // do something, exclude your file
}

Alternatively you can compare the BUILD_TYPE and use it the same way:

if(BuildConfig.BUILD_TYPE.equals("release"))
{
    // do something, exclude your file
}

Implement this in the relevant task and you are good to go. Also this and this answers explain how to achieve what you want to do very nicely.

By the way, you can wrap aaptOptions in a release closure like this:

release {
    aaptOptions {
        ignoreAssetsPattern 'file.json' // Your file pattern
    }
}
UnlikePluto
  • 3,101
  • 4
  • 23
  • 33