butterknife异常提示:attribute value must be constant

就是因为你的android工程是lib类型的

如:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

这样你在R.id.xxx 取R中变量的时候并非是final类型,所以只能老老实实findviewbyid了!!!

***当然想要把R中变量改为final也是可行的,可能需要在打包的过程中利用脚本把Libray的R中字段替换;有兴趣的可以研究下哦!

原文地址:https://www.cnblogs.com/zzq-include/p/5930331.html