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++ 編程工具的功能...