Add folder to srcDir, except for one file in gradle

I am developing an Android application with several options:

sourceSets {
    main {
        res.srcDirs += ["headend/ott/res"]
    }

    flavor1 {
        res.srcDirs += ["src/module1/res-splash"]
    }

    flavor2 {
        java.srcDirs += ["src/module1/java"]
        res.srcDirs += ["src/module1/res"]
        res.srcDirs += ["src/module2/res"]
        assets.srcDirs += ["src/module1/assets"]
    }

    test {
        res.srcDirs += ["src/test/resources"]
    }
    ...

My problem is that in flavor2, some of the resources of module2 should be a replacement for those that are already present in module1, but with my current approach this leads to a build failure with duplicate resources.

So, I need a way to add "src / module1 / res" to flavor2, but not including one specific file.

I tried

res{
    srcDirs += ["src/module1/res"]
    res.srcDirs += ["src/module1/res"]        
    exclude 'src/module1/res/drawable/specific_file.xml'
}

But to no avail.

Is this even possible?

+4
source share
2 answers

, , , . , , , .

, , . / flavour2 .

sourceSets {
    flavor2 {
        res {
            srcDirs += ["src/module1/res"]
            srcDirs += ["src/module2/res"]
        }
    }
 }

resources_discard.xml module2/res/raw :

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" 
         tools:discard="@drawable/specific_file.xml" />
+1

. java , srcDir exclude. exclude srcDir.

res{
    srcDirs += ["src/module1/res"]
    res.srcDirs += ["src/module1/res"]        
    exclude 'drawable/specific_file.xml'
}
0

Source: https://habr.com/ru/post/1694922/


All Articles