美文网首页Android学习
解决在Studio3.1.2的library工程中使用Butte

解决在Studio3.1.2的library工程中使用Butte

作者: 青峰星宇 | 来源:发表于2018-06-29 10:59 被阅读24次

运行环境

win7_64
studio3.1.2
Butterknife8.8.1

当在module中使用butterknife时,会提示Attribute value must be constant,如下图1-2所示:

1-2.png

解决方法:

1).在根目录下的build.gradle中的dependencies添加如下:
这里注意是8.4.0的版本!!

buildscript {
  repositories {
      google()
      jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
  }
 }

2).在你module中的build.gradle顶部t添加如下代码:

    apply plugin: 'com.android.library'
    apply plugin: 'com.jakewharton.butterknife'

3).最后,在module中的build.gradle 中的dependencies中添加:

dependencies {
  compile 'com.jakewharton:butterknife:8.8.1'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

4)然后在module中使用R2代替R来findViewById即可,如下图1-3所示:


1-3.png

以上就是解决如何在在library中使用butterknife

相关文章

网友评论

    本文标题:解决在Studio3.1.2的library工程中使用Butte

    本文链接:https://www.haomeiwen.com/subject/quooyftx.html