ButterKnife随笔

2018-10-12  本文已影响0人  衣谷文武

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()

}

}

上一篇 下一篇

猜你喜欢

热点阅读