發現如何IntelliJ IDEA下配置AndroidAnnotations國内沒有任何教程,感覺有必要分享一下自己遇到的問題并如何解決。希望有助于大家~
1、安裝Intellij IDEA,這個不是我要說的重點,官網都有。
2、建立一個Android工程。
3、下載下傳AndroidAnnotations library。解壓後會有androidannotations-api-2.7.1.jar 和androidannotations-2.7.1.jar 把後者放到工程下compile-libs檔案夾,沒有的話建立改名.
4、修改工程的依賴包選項,導入API包。如下圖所示
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLx8VYh9CXyFWTvwFNxAjMvw1cldWYtl2LcRnblRnbvN2Lc12bj5Cdm92ct0WZ09GdusWdoNWYrRXYvw1LcpDc0RHaiojIsJye.png)
5、File -> Settings -> Compiler -> Annotation Processors. 設定成如下圖所示,這裡我要說明幾點首先設好Path指向you_project_path\compile-libs\androidannotations-2.7.1.jar !!!
其次store generated sources relative to選擇後者
6、設定Run Configurations屬性如下圖所示,别忘了把AndroidMainfest.xml裡的activitie name 一并改了:
7、設定生成檔案夾 Project Structure -> Modules -> Sources tab -> right click on generated folder -> Sources.如下圖:
7、重新編譯,類似Eclipse的clean功能,Build -> Rebuild Project 然後運作看下效果!
最後代碼中使用AndroidAnnotations library 後跳轉時必須如下寫 ActivityName + _ suffix. 像:
startActivity(this, MyListActivity_.class);