gradle-androidannotations-plugin icon indicating copy to clipboard operation
gradle-androidannotations-plugin copied to clipboard

Add support for the official Android Gradle plugin

Open devesh opened this issue 12 years ago • 4 comments

http://tools.android.com/tech-docs/new-build-system/user-guide

devesh avatar Feb 17 '13 05:02 devesh

Will this ever be done?

artiomchi avatar Apr 01 '13 18:04 artiomchi

I've described how I hacked up my build.gradle directly here: https://github.com/excilys/androidannotations/issues/517#issuecomment-14355119

You can do the same thing until somebody who understands gradle better than I do makes a nice plugin.

devesh avatar Apr 01 '13 18:04 devesh

I just found that, actually and ended up using it too :)

Thanks for your great work!

artiomchi avatar Apr 01 '13 18:04 artiomchi

Just to update this issue, with the actual version of gradle (0.4.2) I'm using the following recipe in my gradle builds:

  • for dependencies:
configurations {
    apt
}

dependencies {
    apt group: "com.googlecode.androidannotations", name: "androidannotations", version: "2.7.1"
    compile group: "com.googlecode.androidannotations", name: "androidannotations-api", version: "2.7.1"
}
  • to compile with AA support:
afterEvaluate {
    android.applicationVariants.each { variant ->
        def aptOutputDir = file("${project.buildDir}/source/apt/${variant.dirName}")

        variant.javaCompile.doFirst {
            aptOutputDir.mkdirs()
            variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.apt.getAsPath(),
                '-AandroidManifestFile=' + variant.processResources.manifestFile,
                '-s', aptOutputDir
            ]
        }
    }
}

I choose the build/sources/apt because every generated code goes to build/sources, e.g BuildConfig and R classes. This way I didn't need to configure extra clean paths and don't feel hacky IMO.

The only problem that I found was with Android Studio, which don't see the extra folder as a source root. To fix this issue I have to manually set the build/source/apt/debug as source folder, and the IDE doesn't remember this configuration after restart/synching. Is annoying but doable.

andrewhr avatar Jun 21 '13 12:06 andrewhr