ButterKnife随笔

ButterKnife是很好用的一个三方注入依赖包。

使用Butterknife时可能会出现NullPointerException

如下为参考解决方案:

buildscript {

repositories {

google()

jcenter()

}

dependencies {

    classpath'com.android.tools.build:gradle:3.0.1'

    classpath'com.jakewharton:butterknife-gradle-plugin:8.5.1'

        // NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

    }

}


然后在app中build.gradle中添加:

applyplugin:'com.jakewharton.butterknife'


在dependencies中添加

implementation'com.jakewharton:butterknife:8.5.1'

annotationProcessor'com.jakewharton:butterknife-compiler:8.5.1'

gradle版本改为了4.1

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

这是低版本butterknife 8.5.1高于这个版本会出错

把butterknife版本设为8.8.1,在gradle sync过程就会出错:

Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'.

Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

修改方法:

buildscript {

repositories {

maven { url'https://oss.sonatype.org/content/repositories/snapshots' }

google()

jcenter()

}

dependencies {

classpath'com.android.tools.build:gradle:3.1.3'

        classpath'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'

        // NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

    }

}

allprojects {

repositories {

maven { url'https://oss.sonatype.org/content/repositories/snapshots' }

google()

jcenter()

}

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 博客原文链接 Android百大框架排行榜(转) 说明: 无聊写一篇笔记式文章. 精力有限,很多错误之处,受时间与...
    码农朱同学阅读 8,125评论 0 27
  • 请允许我借鉴前辈们的东西~~~~ 感激不尽~~~~~ 以下为Android 框架排行榜 么么哒~ Android...
    嗯_新阅读 6,727评论 3 32
  • 一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由、网络层、UI层、通信层或其他单一功能的框架 混合开发框架:...
    伟子男阅读 10,634评论 0 161
  • 附上原文作者连接:作者:金诚 一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由、网络层、UI层、通信层或其他...
    这个美嘉不姓陈阅读 6,718评论 1 35
  • 《唤醒内在天才的秘密》 作者:李胜杰、林青贤 营养早餐(20180512) ——《唤醒内在天才的秘密》摘录: 孩子...
    觉之灯阅读 1,400评论 0 0

友情链接更多精彩内容