【问题标题】:Android Studio: Use AndroidAnnotationsAndroid Studio:使用 AndroidAnnotations
【发布时间】:2013-05-10 17:32:49
【问题描述】:

所以我想尝试新的 Android Studio 并导入我的 eclipse 项目(我生成了一个 gradle 构建文件)。效果不错。

似乎唯一不起作用的库是 AndroidAnnotations。 我在 File > Settings > Compiler > Annotation Processing 下选择了 androidannotations-2.7.jar 文件。

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

【问题讨论】:

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


    【解决方案1】:

    我遇到了同样的问题,按照使用 intelliJ 配置 aa 的说明进行操作,现在它可以像魅力一样工作了。

    AA intelliJ 配置页面会将您指向这篇文章...

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

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

    在 Eclipse 中我不必做的主要事情是转到 Preferences > Compiler > Annotation Processors 并将我的处理器路径设置为...

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

    【讨论】:

    • Android Studio 1.2 中似乎已移除此选项。
    • 感谢 Ben 的提醒,我还没有升级,
    【解决方案2】:

    这对我有用:

    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

    【讨论】:

    • 标记目录已被删除(无论如何它在 0.3.4 中都不存在)。
    【解决方案3】:

    如果编译没有问题,并且在 IDE 中看到生成的类之后,则需要检查 target/generated-sources/annotations 是否被检查为 Source Folder .

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

    【讨论】:

      【解决方案4】:

      由于 Android Studio 基于 IntelliJ,您是否尝试关注 AndroidAnnotation wiki 上的 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。我会尽快检查的。

      【讨论】:

      • 我完成了他们提供的教程,但无法正常工作。我稍后会尝试您链接的插件。
      • 首先,这个插件是github.com/jvoegele/gradle-android-plugin 的封装,与Android Studio 无关。
      【解决方案5】:

      似乎有一种方法可以让 Android Studio 与 AndroidAnnotations 一起工作

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

      【讨论】:

        【解决方案6】:

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

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

        问题是没有找到 R 类。默认情况下,Android Studio 不会像 eclipse 那样将 R.java 放入 gen 目录。解决方案是进入 Project Settings -> Facets -> 为您的项目选择 Android facet -> Compiler 选项卡,然后将“R.java 和 Manifest.java 文件”从“Run process-resources Maven task before Make”更改为“由 IDE 生成”。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-30
          • 2011-11-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多