如何在Android Studio中设置ButterKnife插件? [英] How to setup ButterKnife plugin in Android Studio?

查看:58
本文介绍了如何在Android Studio中设置ButterKnife插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要安装插件Butter Knife.我在哪里可以下载?我下载了.jar插件(如果文件是我需要的插件,则不是),我已经安装了,但是当我单击生成"选项时,没有出现使用黄油刀的选项.在视频教程之后,我修改了Gradle构建文件:现在,它们如下:

I need to install the plugin Butter Knife. Where can I download it? I downloaded a .jar plugin (but not if the file is the one I need), I have installed but when I click on the option "generate" not the option to use butterknife appears. following a video tutorial I modified files Gradle build: I have them now as follows:

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 to synchronize I get this error:

"android android-library或插件必须应用于项目" 错误(1.0)

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

我在做什么错了?

推荐答案

使用ButterKnife库的最简单方法是将此单行添加到模块级build.gradle依赖项列表中:

The easiest way to use ButterKnife library is to add this single line to your module-level build.gradle dependencies list:

dependencies {
  implementation 'com.jakewharton:butterknife:7.0.1'
}

然后您可以同步您的项目!

You can then synchronize your project!

更新1

我只是注意到自上次使用以来,沃顿商学院的杰克(Jake Wharton)已对其进行了更新!现在,您似乎必须添加到两个单独的位置:

I just noticed Jake the Wharton has updated the library since the last time I used it! Now, it appears you have to add to two separate places:

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

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

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

And lastly, in your module-level build.gradle file:

apply plugin: 'android-apt'

android {
  ...
}

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

重要的是,将apply plugin: 'android-apt'添加到module-level build.gradle文件的顶部;很可能在第一行下面是这样的:

It is important that you add apply plugin: 'android-apt' to top of the module-level build.gradle file; most likely below the first line like this:

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

我刚刚对此进行了测试并为我工作.祝你好运!

I have just tested this and works for me. Good luck!

更新2

Jake Wharton刚刚发布了对该库的更新,这是您使用它需要做的事情:

Jake Wharton just released an update to the library and here is what you need to do in order to use it:

因此,在您的build.gradle (app-level)内部,将以下内容添加到您的依赖项中!

So, inside your build.gradle (app-level), add the following to your dependencies!

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

希望对您有帮助!

更新3:

此处已发布到现在的版本,以防您与其他库发生冲突并想要它在较旧的API级别上工作

尝试一下,直到现在为止,您必须达到SDK最低15级 您需要使用一些版本来使其在我的情况下可以正常工作 到目前为止,至少与SDK 15兼容.

With trying , in case you want it min SDK level 15 till now you will need to play with versions to get it working in my case these set are compatable so far with SDK 15 as minimum.

在这种情况下,我只将它们放在模块应用程序级别build.gradle中.

This case i only put these in module app level build.gradle.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:24.2.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
    implementation group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.3.0'

    implementation 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

    implementation 'io.reactivex:rxjava:1.1.6'
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'

    implementation 'com.android.support:recyclerview-v7:24.2.1'
}

这篇关于如何在Android Studio中设置ButterKnife插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆