Android Studio使用ButterKnife各種錯誤解決Plugin with id 'android-apt' not found.

ButterKnife可以幫助我們查找控件,添加事件綁定等等,可以減少很多代碼,但是在使用過程中對新手來說,往往會碰到很多坑。
AndroidStudio常見報錯如下:
1、Gradle DSL method not found: 'apt()'
2、Plugin with id 'android-apt' not found.
3、Error:Could not find com.android.tools.build:gradle:1.2.3.
Searched in the following locations:
如何使用ButterKnife:
1、首先我們要使用,就需要引入相關的依賴包:
引入依賴包只需要在module的build.gradle文件的dependencies中添加下面兩句:
compile'com.jakewharton:butterknife:8.4.0'
apt'com.jakewharton:butterknife-compiler:8.4.0'
2、然後我們點擊Sync project with Gradle Files按鈕進行同步,然後就報錯了,錯誤如下:
E:\workspace\androidStudio\Project_YZ\LvBuBike_source\app\build.gradle
Error:(47, 0) Gradle DSL method not found: 'apt()'
Possible causes:<ul><li>The project 'LvBuBike_source' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>
意思是沒找到apt方法,我們只要在mobule的build.gradle文件的頂部添加這一句就行了:
applyplugin:'android-apt'
3、接着我們再進行同步,又報瞭如下錯誤:
E:\workspace\androidStudio\Project_YZ\LvBuBike_source\app\build.gradle
Error:(2, 0) Plugin with id 'android-apt' not found.
<a href="openFile:E:\workspace\androidStudio\Project_YZ\LvBuBike_source\app\build.gradle">Open File</a>
解決辦法,在mobule的build.gradle文件中添加這樣一段代碼就ok了
buildscript {
repositories {
jcenter()
}
dependencies {
classpath'com.android.tools.build:gradle:1.2.3'
classpath'com.neenbedankt.gradle.plugins:android-apt:1.4'//Added line
}
}
4、如果在buildscript中只添加了dependencies,而沒有添加repositores的話,會報如下錯誤:
Gradle 'LvBuBike_source' project refresh failed
Error:Could not find com.android.tools.build:gradle:1.2.3.
Searched in the following locations:
file:/D:/software/developer/AS_/setlocation/as/gradle/m2repository/com/android/tools/build/gradle/1.2.3/gradle-1.2.3.pom
file:/D:/software/developer/AS_/setlocation/as/gradle/m2repository/com/android/tools/build/gradle/1.2.3/gradle-1.2.3.jar
Required by:
LvBuBike_source:app:unspecified
5、總結來說不要忘了這三個地方
applyplugin:'android-apt'
compile'com.jakewharton:butterknife:8.4.0'
apt'com.jakewharton:butterknife-compiler:8.4.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath'com.android.tools.build:gradle:1.2.3'
classpath'com.neenbedankt.gradle.plugins:android-apt:1.4'//Added line
}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章