I'm trying to write a plugin for the AndroidAnnotations project. For those who don't know that project, it generates superclass from annotated classes, like activities for instance, with apt.
Currently to make things work with the android gradle plugin, I need to add the following code in my build.gradle :
android.applicationVariants.each { variant ->
// Add special compile for Android Annotations
def aptOutput = project.file("${project.buildDir}/source/apt_generated/${variant.dirName}")
variant.javaCompile.doFirst {
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-AresourcePackageName=net.tsoft.resetunreadsms',
'-s', aptOutput
]
}
}
I want to write a gradle plugin to perform the same thing, so I wrote this :
class AndroidAnnotationGradlePlugin implements Plugin<Project> {
void apply(Project project) {
project.android.applicationVariants.each { variant ->
// Add special compile for Android Annotations
def aptOutput = project.file("${project.buildDir}/source/apt_generated/${variant.dirName}")
variant.javaCompile.doFirst {
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-AresourcePackageName=net.tsoft.resetunreadsms',
'-s', aptOutput
]
}
}
}
}
But I get the following error when executing gradle assembleDebug :
A problem occurred evaluating root project 'MyProject'.
> Android tasks have already been created.
This happens when calling android.applicationVariants,
android.libraryVariants or android.testVariants.
Once these methods are called, it is not possible to
continue configuring the model.
It seems not possible to access applicationVariants from another plugin, is there another way to do it ?
Thanks in advance