Android Studio 0.4 &牛油刀 [英] Android Studio 0.4 & Butter Knife

查看:25
本文介绍了Android Studio 0.4 &牛油刀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得 Android Studio 0.4(gradle 项目)&Jake Wharton 的 Butter Knife 一起玩得很好.对视图的引用(应该注入的 ViewPager 始终为 null.

I'm unable to get Android Studio 0.4 (gradle project) & Jake Wharton's Butter Knife to play well together. The reference to the view (ViewPager that's supposed to get injected is always null.

我已经尝试启用注释处理(设置 -> 编译器 -> 注释处理器 -> 启用注释处理)和清理,但它仍然不起作用.

I've tried enabling annotation processing (Settings -> Compilers -> Annotation Processors -> Enable annotation processing) and cleaning, but it still doesn't work.

编辑:如果相关,我尝试注入的视图是 android.support.v4.view.ViewPager

Edit: In case it's of relevance, the view I'm trying to inject is a android.support.v4.view.ViewPager

编辑 2:完整的解决方案:

buildScript {
    repositories {
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        ...
        classpath 'com.jimdo.gradle:gradle-apt-plugin:0.2-SNAPSHOT'
    } }

apply plugin: 'apt'

android {       
    butterknifeVersion = '4.0.1'
    dependencies {
        apt "com.jakewharton:butterknife:${butterknifeVersion}"
        compile "com.jakewharton:butterknife:${butterknifeVersion}"
    }
}

推荐答案

在编译前尝试运行注解处理工具

Try run the annotation processing tool before the compile

dependency {
     apt 'com.jakewharton:butterknife:(insert latest version)'
     compile 'com.jakewharton:butterknife:(insert latest version)'
}

看看这个:https://stackoverflow.com/a/20742913/1473536

这篇关于Android Studio 0.4 &牛油刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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