Question

I've got Android Studio and Android Annotations working fine, though I'm having to add

<sourceFolder url="file://$MODULE_DIR$/build/source/apt_generated/defaultFlavor/debug" isTestSource="false" generated="true" />

to my .iml file each time I start Android Studio for it to pick up my generated classes.

This is in my build.gradle:

android.applicationVariants.all { variant ->
    aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
    println "****************************"
    println "variant: ${variant.name}"
    println "manifest:  ${variant.processResources.manifestFile}"
    println "aptOutput:  ${aptOutput}"
    println "****************************"

    variant.javaCompile.doFirst {
        println "*** compile doFirst ${variant.name}"
        aptOutput.mkdirs()
        variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.apt.getAsPath(),
                '-AandroidManifestFile=' + variant.processResources.manifestFile,
                '-s', aptOutput
        ]
    }
}

Is there any way to get Android Studio to pick up the apt_generated folder?

Was it helpful?

Solution

In Android Studio 0.3.6, there's no supported way to have it add build/sources/apt-generated/debug as a source root. What you're doing by adding it manually to the .iml file works temporarily as you see, but those changes are lost every time it re-syncs to the Gradle build files. The previous workaround of using the "Mark Directory As" command no longer works because that has been removed from Android Studio until we can get it working properly; in any event, before its removal that command effectively did the same thing as modifying the .iml file by hand, with the same result that changes were lost on re-sync.

We already know about issues with needing to set source roots to support Roboelctric; however, I've filed https://code.google.com/p/android/issues/detail?id=62747 to track Androidannotations as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top