Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Use AndroidAnnotations

So I wanted to try the new Android Studio and imported my eclipse projects (I generated a gradle build file). Worked pretty good.

The only library which does not seem to work is AndroidAnnotations. I selected the androidannotations-2.7.jar file under File > Settings > Compiler > Annotation Processing.

As production source directory i selected "gen". But the generated file like MainActivity_ are not generated. What did I wrong?

like image 387
Basic Coder Avatar asked May 16 '13 00:05

Basic Coder


2 Answers

I had the same issues, followed the instructions for configuring aa with intelliJ, now it works like a charm does.

AA intelliJ config page will point you to this post...

http://www.ashokgelal.com/2012/12/setting-up-intellij-idea-12-with-maven-actionbarsherlock-roboelectric-androidannotations/

...the above post walks you through setting up various libs in intelliJ, scroll towards the bottom for AA.

The main thing I had to do that I did not have to do in eclipse was go to Preferences > Compiler > Annotation Processors and set my Processor Path to something like...

[PATH TO AA JARS]/androidannotations-2.7.jar:[PATH TO AA JARS]/androidannotations-api-2.7.jar:[PATH TO AA JARS]/codemodel-2.4.1.jar

like image 157
Grant Caesar Peters Avatar answered Sep 23 '22 23:09

Grant Caesar Peters


This is what works for me:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'

configurations {
    apt
}

repositories {
    mavenRepo url: 'https://oss.sonatype.org/content/repositories/snapshots/'
}

ext.androidAnnotationsVersion = '3.0-SNAPSHOT';

dependencies {
    compile 'com.android.support:support-v4:18.0.+'

    apt "org.androidannotations:androidannotations:$ext.androidAnnotationsVersion"
    compile "org.androidannotations:androidannotations-api:$ext.androidAnnotationsVersion"
}

android {
    compileSdkVersion 18
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

android.applicationVariants.all { variant ->
    ext.aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
    ext.aptOutput.mkdirs()

    variant.javaCompile.options.compilerArgs += [
            '-processorpath', configurations.apt.asPath,
            '-AandroidManifestFile=' + variant.processResources.manifestFile,
            '-s', ext.aptOutput
    ]
}

After that I need to mark build/sources/apt-generated/debug as source in Android Studio by right clicking it and selecting Mark Directory as > Source Root

like image 38
César Izurieta Avatar answered Sep 25 '22 23:09

César Izurieta