如何在Android Studio中设置ButterKnife插件?

前端之家收集整理的这篇文章主要介绍了如何在Android Studio中设置ButterKnife插件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要安装黄油刀.在哪里可以下载?我下载了一个.jar插件(但是如果该文件是我需要的那个文件),我已经安装了,但是当我点击选项“生成”时,不会出现使用butterknife的选项.接下来的一个视频教程我修改文件Gradle build:我现在有了如下:
apply plugin: 'android-apt'
apply plugin: 'com.android.application'


android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "calcursoedxleccion0.cal"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs',include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.ext.supportLibraryVersion"
    compile "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.ext.supportLibraryVersion"

   // compile "com.jakewharton:butterknife:$rootProject.ext.butterKnifeVersion"
    compile "com.jakewharton:butterknife:$rootProject.ext.butterKnifeVersion"


   apt "com.jakewharton:butterknife-compiler:8.0.1"
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext{

    minSdkVersion = 16
    targetSdkVersion = 23
    compileSdkVersion = 23
    buildToolsVersion = '23.0.3'

    supportLibraryVersion = '23.3.0'
    butterKnifeVersion = '8.0.1'
}

Gradle来同步我得到这个错误

“The android android-library or plugin must be applied to the project”
error (1.0)

我究竟做错了什么?

解决方法

使用ButterKnife库最简单的方法是将此单行添加到模块级build.gradle依赖关系列表中:
dependencies {
  compile 'com.jakewharton:butterknife:7.0.1'
}

您可以同步您的项目!

UPDATE

我刚刚注意到Jake从上次使用它以来,沃顿更新了图书馆!现在,您必须添加到两个不同的地方:

在您的项目级build.gradle文件中:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  }
}

最后,在你的模块级build.gradle文件中:

apply plugin: 'android-apt'

android {
  ...
}

dependencies {
   compile 'com.jakewharton:butterknife:8.0.1'
   apt 'com.jakewharton:butterknife-compiler:8.0.1'
}

您应该将应用程序插件添加到模块级build.gradle文件的顶部:“android-apt”很可能低于这样的第一行:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

我刚刚测试过,并为我工作.祝你好运!

原文链接:https://www.f2er.com/android/311833.html

猜你在找的Android相关文章