Android Studio:使用AndroidAnnotations

时间:2013-05-16 00:12:36

标签: android intellij-idea android-annotations android-studio

所以我想尝试新的Android Studio并导入我的eclipse项目(我生成了一个gradle构建文件)。工作得很好。

唯一似乎不起作用的库是AndroidAnnotations。 我选择了File>下的androidannotations-2.7.jar文件。设置>编译器>注释处理。

作为生产源目录,我选择了“gen”。 但是不会生成像MainActivity_这样的生成文件。我错了什么?

6 个答案:

答案 0 :(得分:11)

我遇到了同样的问题,按照使用intelliJ配置aa的说明,现在它就像魅力一样。

AA intelliJ配置页面会指向你的帖子......

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

...上面的帖子引导您在intelliJ中设置各种库,向AA滚动到底部。

我必须做的主要事情是我在eclipse中不必做的是转到首选项>编译器>注释处理器并将我的处理器路径设置为类似......

  

[途径到AA JARS] /androidannotations-2.7.jar:[路径到AA   JARS] /androidannotations-api-2.7.jar:[路径到AA   JARS] /codemodel-2.4.1.jar

答案 1 :(得分:5)

这对我有用:

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
    ]
}

之后,我需要在Android Studio中将build/sources/apt-generated/debug标记为来源,方法是右键单击并选择Mark Directory as> Source Root

答案 2 :(得分:2)

如果编译时没有问题,并且在IDE中看到生成的类之后,则需要检查目标/生成源/注释是否被选为源文件夹

那将是File>项目结构>模块> “源”选项卡,然后查找该文件夹并将其标记为 Sources 。该文件夹将变为蓝色,并将列在“源文件夹”列表中。

答案 3 :(得分:0)

由于Android Studio基于IntelliJ,您是否尝试按照AndroidAnnotation维基上的configuration guideline进行操作?

如果你正在使用gradle,你应该查看this page,它解释了如何配置AndroidAnnotation的插件:

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'

我还没有尝试过这个新的IDE。我很快就会检查一下。

答案 4 :(得分:0)

似乎有一种方法可以让Android Studio与AndroidAnnotations一起使用

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

答案 5 :(得分:0)

如果您尝试将Android Studio与运行Android Annotations的项目一起使用,则可能会遇到一个神秘的编译器问题:

为注释元素找到错误输入的数据public abstract int com.googlecode.androidannotations.annotations.EActivity.value()(找到int类型的数据)

问题是找不到R类。默认情况下,Android Studio不会将R.java放入gen目录中。解决方案是进入项目设置 - >方面 - >选择项目的Android方面 - >编译选项卡,并将“R.java和Manifest.java文件”从“在Make之前运行process-resources Maven任务”更改为“由IDE生成”。