1.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
}
}
---------------------
原文:https://blog.csdn.net/u010937230/article/details/60762472
- 2.Gradle DSL method not found: 'apt()'
经过我仔细观察后,发现是我主工程下的build.gradle文件中没有引用 android-gralde.apt的插件。
解决方案:
在当前.gradle文件中添加:
apply plugin: 'android-apt'
在根目录的build.gradle的dependencies(依赖)下添加一句:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
全部代码如下(不要忘记重新编译哦):
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
是不是很简单呢
原文:https://blog.csdn.net/yanjunhui2011/article/details/52056927