Define a string in gradle and also use a flavor-specific applicationId

Well after a lot of searching I've managed to find the answer to this. Perhaps someone will find this useful.

productFlavors.all {
    resValue "string", "authority", applicationId + ".dataprovider"
}

This simple snippet sets a string to all flavors after their invidual variables have been set. It's kind of like a defaultConfig but not quite since it's executed after the flavor blocks.


Extra:

Turns out I can even set the applicationId! My final result so far is:

def final String AUTHORITY = '.dataprovider'

productFlavors.all {
    applicationId "com.my.app." + name
    resValue "string", "authority", applicationId + AUTHORITY
    buildConfigField "String", "AUTHORITY", "\""+applicationId + AUTHORITY+"\""
}

Now I can get each flavor provider's authority through BuildConfig.AUTHORITY and @string/authority, which I use in the manifest and in my class file respectively:

<provider
    android:name="com.my.app.DataProvider"
    android:authorities="@string/authority"
    android:exported="false" />


public class DataProvider extends ContentProvider {
    public static final String PROVIDER = BuildConfig.AUTHORITY;
    public static final Uri SEARCH_URI = Uri.parse("content://" + PROVIDER + "/search");
}