Is there any way to add extra source folder to each Build Variant in build.gradle?
I'd like to use Pluggable Annotation Processing API (JSR 269).
an extra source folder.
android.applicationVariants.each { variant ->
def aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
variant.javaCompile.doFirst {
aptOutput.mkdirs()
aptOutput.eachFileRecurse groovy.io.FileType.FILES, {
it.delete()
}
variant.javaCompile.options.compilerArgs += [
'-processorpath', "<path of factory jar>",
'-s', aptOutput
]
}
}
I found two ugly workarounds.
First, I used "${project.buildDir}/source/r/${variant.dirName}" instead of
"${project.buildDir}/source/apt_generated/${variant.dirName}".
Second workaround, I took over 'sourceOutputDir' of Renderscript.
tasks["compile${variant.name}Renderscript"].sourceOutputDir = aptOutput
It worked, and it's too ugly...
These two workarounds completely work with Build Variant switching in Android Studio,
but I'd like to avoid these ugly way...
any suggestions?