Can I add extra soure folder?

Skip to first unread message

Makoto Yamazaki

Jun 20, 2013, 11:16:23 AM6/20/13

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).

I wrote build.gradle to use PAP as follows, but I couldn't find the way to add 
"${project.buildDir}/source/apt_generated/${variant.dirName}" as
an extra source folder.

android.applicationVariants.each { variant ->
    def aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")

    variant.javaCompile.doFirst {
        aptOutput.eachFileRecurse, {
        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 

Second workaround, I took over 'sourceOutputDir' of Renderscript.
tasks["compile${}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?

Xavier Ducrohet

Jun 20, 2013, 1:11:15 PM6/20/13
There's no easy way to do this now, it's all going to be ugly.

You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Xavier Ducrohet
Android SDK Tech Lead
Google Inc. |

Please do not send me questions directly. Thanks!
Reply all
Reply to author
0 new messages