我已经能够使用 gradle(以及 Dagger)成功运行 AndroidAnnotations,但是一旦我尝试将storm-apt 添加到生成器中,gradle 就会默默地失败,跳过所有注释处理。
这是一个示例 build.gradle 可以工作(即运行 aa apt 处理器,但不运行storm apt 处理器),但没有包含storm-apt jar 的行,但会失败(即无法运行aa apt 处理器,以及风暴 apt 处理器)与它:
import groovy.io.FileType
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
repositories {
mavenCentral()
}
ext.androidAnnotationsVersion = '2.7.1'
configurations {
apt
}
dependencies {
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
// commenting out the following line will allow the aa apt processor to complete,
// while leaving it uncommented will cause all annotation processing,
// both aa and storm to silently fail
apt files('libs/storm-apt-0.97.jar')
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
compile files('libs/storm-api-0.97.jar')
}
afterEvaluate { project ->
android.applicationVariants.each { variant ->
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
ext.aptOutput = file("${project.buildDir}/source/r/${variant.dirName}")
aptOutput.mkdirs()
aptOutput.eachFileRecurse FileType.FILES, {
if (it.name.equals('R.java')) {
return
}
it.delete()
}
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-s', aptOutput
]
println "*** ${variant.javaCompile.options.compilerArgs}"
}
}
}