Gradle sync failed: Plugin with id 'com.neenbedankt.android-apt' not found.

Android Studio 运行项目报错显示
** " Gradle sync failed: Plugin with id 'com.neenbedankt.android-apt' not found. "</br>
——> com.neenbedankt Gradle同步失败:插件id,android-apt”未找到。**

</br>
解决步骤如下:</br>
1、安装butterknife插件。
2、在项目顶层的build.gradle文件中添加依赖项,如下:
<pre>
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
</pre>
3、然后在app的build.gradle里面添加插件的引用以及需要依赖哪些库,如下:</br>
<pre>
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'la.dahuo:command:1.0.0'
apt 'la.dahuo:command-codegen:1.0.0'
}
</pre>
注意上面的apt ‘la.dahuo:command-codegen:1.0.0’,这里表示引用一个注解处理器的库,这个库的代码最终不会进入编译出来的APK里面。
</br>
4、使用注解生成代码,上面出现的库la.dahuo:command、la.dahuo:command-codegen就是我根据命令设计模式(Command Design Pattern)写的一个注解库,它用来让我们方便的生成代码,看下用法:
</br>
<pre>定义Command
@CommandDef("commandName")
public class MyCommand extends Command {
@Param
String paramStr;
@Param("paramIntName")
int paramInt;
@Override
public void execute() {
// do something with params
}
}
</pre>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,330评论 25 709
  • 前期一部热播的职场电视剧《我的前半生》,引起了职场人广泛热议,尤其是其中的职场精英贺涵、唐晶的一些精典台词,更是引...
    第一任职阅读 7,188评论 0 3
  • 宝宝来了,而宝宝也会来. 宝宝的来路漫长,而宝宝来的路既漫长又艰辛。
    地不久天不长阅读 1,709评论 0 0
  • 作为一个近视眼儿,又只在需要的时候,比如开车、打电脑、逛街才戴眼镜的人来说,这个世界大部分情况下在我的眼中是模糊的...
    营养私教西西阅读 1,716评论 0 0