简体   繁体   English

Android Studio批注设置

[英]Android Studio annotations setup

I'm trying to use AndroidAnnotations in Android Studio. 我正在尝试在Android Studio中使用AndroidAnnotations。 What's difference between "store generated sources relative to module output directory " and "store generated sources relative to module content root "? “相对于模块输出目录的存储生成的源”和“相对于模块内容根的存储生成的源”之间有什么区别?

I searched in Intellij Idea manual but found nothing. 我在Intellij Idea手册中进行了搜索,但未找到任何内容。

I guess you are using Gradle. 我猜您正在使用Gradle。 In your build.gradle : 在您的build.gradle

1) Configure the APT plugin: 1)配置APT插件:

apply plugin: 'android-apt'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'your.package.here'
    }
}

2) Add the AA dependency in your build.gradle 2)在您的build.gradle添加AA依赖build.gradle

apt "org.androidannotations:androidannotations:3.0"
compile 'org.androidannotations:androidannotations-api:3.0'

You can see the AndroidAnnotations generated classes in build/generated/source/apt/debug/your.package.here 您可以在build/generated/source/apt/debug/your.package.here Generated build/generated/source/apt/debug/your.package.here看到AndroidAnnotations生成的类。

I tried several ways to get my project to build with Dagger2 and AA. 我尝试了几种方法来使我的项目使用Dagger2和AA进行构建。 What ended up solving my issue was having both 最终解决了我的问题的是

apply plugin: 'com.neenbedankt.android-apt' 
apply plugin: 'android-apt'

In the project gradle I have 在项目gradle中,我有

 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

In my app gradle file I have 在我的应用程序gradle文件中

def AAVersion = '4.2.0'
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"

This seems to be working. 这似乎正在工作。 Previously I was getting the ClassNotDefError. 以前我得到的是ClassNotDefError。 Then I started to get an error about Dagger file not generating. 然后,我开始收到有关未生成Dagger文件的错误。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM