最近公司项目我打算将AA框架用上,但是实际导入后发现会报错:“attribute value must be constant",后来查阅了大量资料,最终才查到原来问题出现在我现在这个工程是一个Library工程,而Library工程生成的R文件不是constant的,因此才会报错,最后我找到了解决办法,方法如下:

原来的注解方式是:

 @ViewById(R.id.circlelogo)    View mCircleView;

@EAvtivity等等方法相类似,都要改成如下的方法:

 @ViewById(resName = "circlelogo")    View mCircleView;

然后我发现光是这样还不够,原本在build过之后,对应的activity应该会生成一个activity_文件,依然没有生成,导致报activity not found的错,通过查询github上AA的官方文档,我找到了解决方法:


“The id fields of the R inner classes of an Android project, such asR.id.someId, arestatic finalconstants. This allows us to use them in annotations parameter, which only accept compile time constant values.

To solve problems related to library projects, the Android team decided that the R inner classes fields of a library project would not bestatic finalanymore. Which means we can't use them in annotations in library projects any more.

You can explicitely tell AA that the project is a library project by setting thelibraryannotation processing optiontotrue.

简单说来就是引用AA框架的时候需要告诉AA这个工程是一个Library工程,方法如下;

在工程的build.gradle中,我们加入框架的时候曾经写过一个apt方法,加入下面的代码:

apt {    arguments {        androidManifestFile variant.outputs[0]?.processResources?.manifestFile        library 'true'        // if you have multiple outputs (when using splits), you may want to have other index than 0        // you should set your package name here if you are using different application IDs        // resourcePackageName "your.package.name"        // You can set optional annotation processing options here, like these commented options:        // logLevel 'INFO'        // logFile '/var/log/aa.log'    }}
Library ‘true’就是告诉AA我们的工程师Library工程,在这里我们还可以对AA加上各种各样的定制,详情请到官网查找:https://github.com/excilys/androidannotations/wiki/CustomizeAnnotationProcessing#library



更多相关文章

  1. 从Eclipse迁移到Android(安卓)Stdio中
  2. Android(安卓)IPC框架分析 Binder,Service,Service manager
  3. Android主流框架RxJava+Retrofit+MVP
  4. Android(安卓)UI框架概览
  5. AndEngine引擎学习之环境配置以及示例修改
  6. Java集合框架——Android中的ArrayList源码分析
  7. Android(安卓)Eclipse中查看 Android框架源码
  8. 网络请求框架(Volley)
  9. Android中使用开源框架Citypickerview实现省市区三级联动选择

随机推荐

  1. Android系统设计中的设计模式分析之一
  2. ADROID 2.1 架构解析 11 系统时间
  3. Android面试知识点复习,那些不为人知的秘
  4. iOS和Android规范解析——工具栏和固定底
  5. 第二阶段--最终作业
  6. 为什么android的R类要定义成16进制
  7. Android webView 支持缩放及自适应屏幕
  8. 2014-7-22 Android SharedPreferences 写
  9. android listview的item里面的imageview
  10. android 调用系统前置摄像头