Android Studio: Use AndroidAnnotations
Asked Answered
A

6

19

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?

Algin answered 16/5, 2013 at 0:12 Comment(0)
S
11

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

Stocktonontees answered 18/5, 2013 at 14:43 Comment(2)
This option seems to have been removed in Android Studio 1.2.Wotan
Thanks for the heads up Ben, I haven't upgraded,Stocktonontees
T
5

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

Torre answered 8/9, 2013 at 18:50 Comment(1)
Mark Directory has been removed (it's not present in 0.3.4, in any case).Iggie
R
2

If you don't have problems compiling and just after seeing the generated classes in the IDE, then you need to check if target/generated-sources/annotations is checked as Source Folder.

That would be File > Project Structure > Modules > Sources Tab, then look for the folder and tag it as Sources. The folder will turn blue and will be listed on the Source Folder list.

Rab answered 17/5, 2013 at 6:58 Comment(0)
C
0

As Android Studio is based on IntelliJ did you try to follow the configuration guideline on AndroidAnnotation's wiki ?

If you're using gradle you should check this page which explains how to configure the AndroidAnnotation's plugin :

buildscript {
    repositories {
        mavenCentral()
    }

    def gradleAndroidAnnotationsPluginVersion = '0.3.0'

    dependencies {
        classpath "net.ealden.gradle.plugins:gradle-androidannotations-plugin:$gradleAndroidAnnotationsPluginVersion"
    }
}

apply plugin: 'androidannotations'
apply plugin: 'idea'

androidAnnotationsVersion = '2.2'

I didn't try this new IDE yet. I'll check that soon.

Calcine answered 16/5, 2013 at 7:48 Comment(2)
I did that tutorial they've provided but I couldn't get things working. I will try the plugin you've linked later.Algin
First, this plugin is a wrapper around github.com/jvoegele/gradle-android-plugin which has nothing to do with Android Studio.Greysun
G
0

It seems there is a way of making Android Studio work with AndroidAnnotations

http://code.google.com/p/android/issues/detail?id=55764

Greysun answered 25/5, 2013 at 15:50 Comment(0)
T
0

If you try to use Android Studio with a project running Android Annotations, you may run into a cryptic compiler issue:

incorrectly typed data found for annotation element public abstract int com.googlecode.androidannotations.annotations.EActivity.value() (Found data of type int)

Problem is the R class is not found. Android Studio doesn't place the R.java into the gen directory by default like eclipse. The solution is to go into Project Settings -> Facets -> Select the Android facet for your project -> Compiler tab, and change the "R.java and Manifest.java files" from "Run process-resources Maven task before Make" to "Generated by IDE".

Toby answered 16/7, 2013 at 13:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.