I am trying to add AndroidAnnotations to Android Studio project that has a gradle build system. Has anyone done this? Can anyone help me with this? I do not even know where to start. I know how to add libraries to gradle but AndroidAnnotations requires 2 jar files and I do not know what should I do.
问问题
9533 次
1 回答
13
After 4 months I am 4 months older and a little smarter :) If you want to use
Annotations in Android use http://jakewharton.github.io/butterknife/.
It is way better and it is easy to set up :)
这是您需要做的:
- 您需要修改 build.gradle 文件(应用程序模块的构建文件)
首先添加匕首和注释版本。您也可以在依赖项中声明它们。当您有很多依赖项时,这会更方便。
ext.daggerVersion = '1.0.0';
ext.androidAnnotationsVersion = '2.7.1';
configurations {
apt
}
添加依赖项:
dependencies {
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"
}
最后,添加这个。这将为编译器添加路径并为生成的文件创建一个目录(此目录将被称为 apt_generated):
android.applicationVariants.each { 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
]
}
}
哦,是的,构建应用程序后,您需要转到项目根目录/build/apt_generated,右键单击文件夹并设置“标记为源根目录”
于 2013-08-01T16:12:01.327 回答