androidannotation
① 安卓注解Android Annotation
在build.gradle中加入依赖:
如果依赖中有appcompat-v7,该包默认依赖support-annotations,不用再配置
support-annotations包中的内容如下:
androidannotations包中的内容如下:
官网:http://androidannotations.org/
关于Android Support注解常用的用法参考:
AndroidAnnotations框架详解
关于AndroidAnnotation注解常用用法参考:
List of all available annotations
参考 Creating an AndroidAnnotations plugin
创建真正的处理类,该类会处理并验证注解
AndroidAnnotations框架详解
Android注解(Annotation)知识点总结整理
官网
Android注解AndroidAnnotation的使用及实现流程分析
② android studio 的annotation processors选项在哪
1> Project 的 build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/moles.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the indivial mole build.gradle files
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4+'
}
}
allprojects {
repositories {
jcenter()
}
}
2> Mole的 build.gradle :
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2+'
android {
compileSdkVersion 22
buildToolsVersion 22.0.1
defaultConfig {
applicationId com.sondon.mayi.hii
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName 1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
apt org.androidannotations:androidannotations:$AAVersion
compile org.androidannotations:androidannotations-api:$AAVersion
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
// if you have multiple outputs (when using splits), you may want to have other index than 0
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}
重新编译一下,即可!
③ Andriod Studio build过程中出现 “android.support.annotation”
React Native生成的android项目在Android Studio中调试,报错“android.support.annotation”包找不到。
报错具体类是react-native-wechat插件中的com.theweflex.react.WeChatMole.java
具体是import android.support.annotation.Nullable的引用提示“Cannot resolve symbol 'Nullable'”
1、新版Android Studio(3.4以后)管理android.support.xxx 相关包改为AndroidX
2、第三方插件中有的还引用android.support.xxx,有的引用androidx,造成冲突
1、首选方案,将android.support.annotation.Nullable的引用改为androidx.annotation.Nullable
其他类似对应关系参考官网 https://developer.android.google.cn/jetpack/androidx/migrate/class-mappings?hl=zh_cn
2、如果无法修改android.support.xxx的引用,可以将gradle.properties中的以下两项设置改为false
android.useAndroidX = true
android.enableJetifier = true
意思是不用androidx进行包管理
同时在build.gradle中的dependencies添加android.support.xxx的依赖
dependencies {
。。。
api 'com.android.support:support-annotations:20.0.0'
。。。
}
以上
④ 到如了v4怎么android.support.annotation
新版本的v4包有android.support.annotation的包,有的话很幸运使用这些注解的话就不会出错,但是旧版本的没有这个包就很悲剧了,比如我.....
现总结一下方法解决这些问题:
1、更新SDK
2、替换v4包
3、导入android-support-annotations.jar的jar。这个jar可以从网络上下载,也可以从sdk安装目录下(E:\InstallPath\sdk\extras\android\support\samples\annotations)找到,没有的话就去下载吧,这个也有新的和旧的区分
⑤ 如何在Intellij中配置Android annotations
Android annotation方法/步骤
1、首先我们要下载一个anntations的jar包,可以在网上搜到。
2、新建一个mole用于演示android anntations的配置。
3、在project文件夹内新建一个 complie-lib文件夹,把刚才的jar包放进去,同时也放在mole的libs文件夹里一个。
4、打开左上角的全局设置 File-Setting。
按照步骤先找到代码的注释选项,然后在右侧的路径里选择刚才新建的complie-lib文件夹内的jar文件,最后点击 Moule content root选项后点击Apply应用。
在Mole上点击右键,打开Mole设置。
在属性选项卡里,点击右侧绿色小加号,选择第一个 添加jar包。
这是添加进去的是Mole下,libs文件夹内的jar包。
打开一个Activity 在类声明上面添加
@EActivity(R.layout.main) //这是main是layout的id
然后注释掉下面的setContentView一句。
点击上方的Build-Make ,会显示错误,但是已经生成了一些文件,我们继续修改。
在AndroidManifest.xml文件夹里,更改原来的.MyActivity的名字为 .MyActivity_ 也就是后面多加一个 _ 。
再次打开Mole设置,在源文件选项卡里把generated设置为源文件,并点击Apply。
点击Run选项,然后选择编辑Run的设置。
将Mole的启动Activity 设置为MyAcivity_。
之后再次Make ,Run 。 App就可以正常执行。
Android annotations 就可以正常使用了。
⑥ 求教:AndroidStdio中错误:程序包android.annotation不存在
击 android 项目,
之后在弹出的菜单上的 Android Tools 里面每个都点一下,
可能是一个 add support package 或 fix project properties 或 android lint 相关的设置。 Lint 只是一个代码检查的功能,就像 unix/linux 上的 C/C++ 编程工具的功能...