I have two flavors of my project:
flavor1 -> packagename: com.example.flavor1
flavor2 -> packagename: com.example.flavor2
Now I want to build a buildvariant of flavor1 and flavor2. The only difference of the buildvariant is another packagename.
My project uses MapFragments and has just one Manifest - so I put the the permission name of MAPS_RECEIVE in my string resource files of the respective flavors.
The question is: how can I replace a string resource of a buildvariant?
I tried the following approach (described in this post):
buildTypes{
flavor1Rev{
packageName 'com.example.rev.flavor1'
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: ['package_permission' : 'com.example.rev.flavor1.permission.MAPS_RECEIVE'])
}
}
But using this I got this error:
Could not find method filter() for arguments [{tokens={package_permission=com.example.rev.flavor1.permission.MAPS_RECEIVE}}, BuildTypeDsl_D ecorated{name=ReplaceTokens, debuggable=false, jniDebugBuild=false, renderscript DebugBuild=false, renderscriptOptimLevel=3, packageNameSuffix=null, versionNameS uffix=null, runProguard=false, zipAlign=true, signingConfig=null}] on BuildTypeD sl_Decorated{name=buderusFinal, debuggable=false, jniDebugBuild=false, renderscr iptDebugBuild=false, renderscriptOptimLevel=3, packageNameSuffix=null, versionNa meSuffix=null, runProguard=false, zipAlign=true, signingConfig=null}.
Do I have to define an own task for the filter method?
EDIT [2013_07_09]:
String in src/flavor1/res:
<string name="package_permission">package_permission</string>
Code in build.gradle to replace the string:
buildTypes{
flavor1Rev{
copy{
from('src/res/'){
include '**/*.xml'
filter{String line -> line.replaceAll(package_permission, 'com.example.rev.flavor1.permission.MAPS_RECEIVE')}
}
into '$buildDir/res'
}
}
}