本文介绍了Android的工作室+摇篮+ Android的注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充 AndroidAnnotations 到Android Studio项目中,有一个摇篮构建系统。有没有人这样做呢?谁能帮我这个?我甚至不知道从哪里开始。我知道如何添加库摇篮,但AndroidAnnotations需要2个jar文件,我不知道我该怎么做。

解决方案

  4个月后,我4个月老,有点小聪明:)如果你想使用
在Android的注解使用http://jakewharton.github.io/butterknife/。
这是更好的方式,很容易设置:)
 

下面是你需要做的:

  • 您需要修改build.gradle文件(构建文件为您的应用程序模块)

首先添加匕首和注释的版本。您也可以在依赖声明它们。这只是更convenientwhen你有很大的依赖性。

  ext.daggerVersion ='1.0.0';
ext.androidAnnotationsVersion ='2.7.1';

配置{
    易于
}
 

添加依赖关系:

 相关性{

容易com.google code.androidannotations:androidannotations:$ {androidAnnotationsVersion}
编译com.google code.androidannotations:androidannotations-API:$ {androidAnnotationsVersion}
容易com.squareup.dagger:匕首编译:$ {daggerVersion}
编译com.squareup.dagger:短剑:$ {daggerVersion}

}
 

Finnaly,添加此。这增加了路径的编译器,并为生成的文件的目录(这DIR将被称为apt_generated):

  android.applicationVariants.each {变种 - >
aptOutput =文件($ {project.buildDir} /来源/ apt_generated / $ {variant.dirName})
的println************
的println变种:$ {variant.name}
的println清单:$ {variant.processResources.manifestFile}
的printlnaptOutput:$ {aptOutput}
的println************

variant.javaCompile.doFirst {
    的println***编译doFirst $ {variant.name}
    aptOutput.mkdirs()
    variant.javaCompile.options.compilerArgs + = [
            '-processorpath',configurations.apt.getAsPath(),
            -AandroidManifestFile ='+ variant.processResources.manifestFile,
            -s,aptOutput
    ]
}
}
 

哦,对了,以后你建立你的aplication,你需要到项目的根/建造/ apt_generated,右键单击文件夹,并设置标记为源根

I am trying to add AndroidAnnotations to Android Studio project that has a gradle build system. Has anyone done this? Can anyone help me with this? I do not even know where to start. I know how to add libraries to gradle but AndroidAnnotations requires 2 jar files and I do not know what should I do.

解决方案
After 4 months I am 4 months older and a little smarter :) If you want to use
Annotations in Android use http://jakewharton.github.io/butterknife/.
It is way better and it is easy to set up :)

Here is what you need to do:

  • You need to modify your build.gradle file (build file for your application module)

First add dagger and annotations version. You can also declare them in dependencies. This is just more convenientwhen you have a lot of dependencies.

ext.daggerVersion = '1.0.0';
ext.androidAnnotationsVersion = '2.7.1';

configurations {
    apt
}

Add dependencies:

dependencies {

apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"

}

Finnaly, add this. This adds path for compiler and creates a dir for generated files (this dir will be called apt_generated):

android.applicationVariants.each { variant ->
aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest:  ${variant.processResources.manifestFile}"
println "aptOutput:  ${aptOutput}"
println "****************************"

variant.javaCompile.doFirst {
    println "*** compile doFirst ${variant.name}"
    aptOutput.mkdirs()
    variant.javaCompile.options.compilerArgs += [
            '-processorpath', configurations.apt.getAsPath(),
            '-AandroidManifestFile=' + variant.processResources.manifestFile,
            '-s', aptOutput
    ]
}
}

Oh, yes, and after you build your aplication, you need to go to project root/build/apt_generated, right click on folder and set "Mark as source root"

这篇关于Android的工作室+摇篮+ Android的注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:05
查看更多