ealden / gradle-androidannotations-plugin

AndroidAnnotations plugin for Gradle
http://androidannotations.org
Apache License 2.0
40 stars 10 forks source link

Add support for the official Android Gradle plugin #5

Open devesh opened 11 years ago

devesh commented 11 years ago

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

artiomchi commented 11 years ago

Will this ever be done?

devesh commented 11 years ago

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.

artiomchi commented 11 years ago

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

Thanks for your great work!

andrewhr commented 11 years ago

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

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"
}
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.