刮刀7.x是否可以与Kotlin M14一起使用? [英] Does butterknife 7.x work with Kotlin M14?

查看:108
本文介绍了刮刀7.x是否可以与Kotlin M14一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Butterknife与一些Kotlin代码以及Java代码一起使用.我知道在M12之前,ButterKnife所需的注释处理功能差强人意或根本不支持.因此,我将活动保留在Java中.它至少在Java中与Butterknife 6.x和preM12 Kotlin一起使用. 我现在正在尝试使用M13和M14的黄油刀7.x.它甚至应该具有注释处理支持,但不适用于我. bind()函数在我的适配器中没有绑定任何用Java编写的内容,也没有绑定在用Kotlin编写的活动中的任何内容.

I'm trying to use Butterknife with some Kotlin code and also Java code. I know that before M12, there was bad or no support for annotation processing that ButterKnife required. So I have kept my activities in Java. It was working at least in Java with Butterknife 6.x and preM12 Kotlin. I'm trying now butterknife 7.x with M13 and M14. It should have even annotation processing support, but it's not working for me. bind() function doesn't bind anything in my adapter which is written in Java nor in activity written in Kotlin.

我在build.gradle(在Github上尝试了最新版本)中使用了此代码:

I'm using this in build.gradle (tried latest version on Github):

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

dependencies {
   provided files('libs/butterknife-annotations.jar')
   kapt files('libs/butterknife-compiler-8.0.0-SNAPSHOT.jar')
   compile 'com.jakewharton:butterknife:8.0.0-SNAPSHOT@aar'
}

这不能编译.我还尝试了"com.neenbedankt.android-apt",它可以编译但绑定无法正常工作.

This doesn't compile. I tried also 'com.neenbedankt.android-apt' which does compile but binding is not working.

我知道 butterknife 中可能尚不支持该功能.但是,有什么破解方法可以使其正常工作吗?

I know that there is probably not support in butterknife for that yet. But is there any hack to get it working?

推荐答案

它与当前版本的Kotlin(1.0.0-beta-3595)兼容,建议您查看android-butterknife 项目,该项目位于JetBrains的

It does work with the current version of Kotlin (1.0.0-beta-3595), I suggest you to take a look at the android-butterknife project which can be found inside the JetBrains's kotlin-examples repo. In short all you need to do is:

  1. 将以下内容添加到您的app/build.gradle文件中:

kapt {
    generateStubs = true
}

  • 将以下行放入同一build.gradle文件的dependencies块内(假设您已经将compile 'com.jakewharton:butterknife:7.0.1'添加到依赖项中):

  • Put the following line inside the dependencies block of the same build.gradle file (assuming you already added compile 'com.jakewharton:butterknife:7.0.1' to your dependencies):

    kapt 'com.jakewharton:butterknife:7.0.1'
    

  • 应该就是这样.

    这篇关于刮刀7.x是否可以与Kotlin M14一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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