Created
September 5, 2013 13:22
-
-
Save Neferetheka/6450034 to your computer and use it in GitHub Desktop.
Correct Gradle build file to use Android annotations library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.5+' | |
} | |
} | |
apply plugin: 'android' | |
repositories { | |
mavenCentral() | |
maven { | |
url 'https://oss.sonatype.org/content/repositories/snapshots/' | |
} | |
} | |
ext.androidAnnotationsVersion = '3.0-SNAPSHOT'; | |
configurations { | |
apt | |
} | |
dependencies { | |
compile 'com.android.support:support-v4:13.0.+' | |
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}" | |
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}" | |
} | |
android { | |
compileSdkVersion 17 | |
buildToolsVersion "17.0.0" | |
defaultConfig { | |
minSdkVersion 10 | |
targetSdkVersion 17 | |
} | |
} | |
def getSourceSetName(variant) { | |
return new File(variant.dirName).getName(); | |
} | |
android.applicationVariants.all { variant -> | |
def aptOutputDir = project.file("build/source/apt") | |
def aptOutput = new File(aptOutputDir, variant.dirName) | |
println "****************************" | |
println "variant: ${variant.name}" | |
println "manifest: ${variant.processResources.manifestFile}" | |
println "aptOutput: ${aptOutput}" | |
println "****************************" | |
android.sourceSets[getSourceSetName(variant)].java.srcDirs += aptOutput.getPath() | |
variant.javaCompile.options.compilerArgs += [ | |
'-processorpath', configurations.apt.getAsPath(), | |
'-processor', 'com.googlecode.androidannotations.AndroidAnnotationProcessor', | |
'-AandroidManifestFile=' + variant.processResources.manifestFile, | |
'-s', aptOutput | |
] | |
variant.javaCompile.source = variant.javaCompile.source.filter { p -> | |
return !p.getPath().startsWith(aptOutputDir.getPath()) | |
} | |
variant.javaCompile.doFirst { | |
aptOutput.mkdirs() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment