我如何获得匕首和奶油刀与摇篮工作吗? [英] How do I get Dagger and Butterknife working with Gradle?

查看:148
本文介绍了我如何获得匕首和奶油刀与摇篮工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的项目,奶油刀伟大的工作要做视图注入。但是我再需要添加匕首以注入依赖。

我添加了注解处理器工具摇篮插件与相应的匕首要求(只显示为简便起见修改后的部分);

  buildScript {
    库{
        行家{
            网址https://oss.sonatype.org/content/repositories/snapshots/
        }
    }
    依赖{
        ...
        类路径'com.jimdo.gradle:gradle这个-的apt-插件:0.2快照
    }
}应用插件:'易'依赖{
    贴切com.squareup.dagger:匕首编译:$ {} daggerVersion    ...
}

在这一点上现在当我建立并运行应用程序打上 @InjectView 注释都没有得到与奶油刀发出的以下调试消息注入的属性;

  D /奶油刀:仰望视图喷射器com.example.MainActivity
D /奶油刀:未找到。试图超com.example.FactListAbstractActivity
D /奶油刀:未找到。试图超android.app.Activity


解决方案

打开了所有我需要做的是增加才能有注解处理器工具皮卡列入奶油刀处理器的另一个贴切的依赖。这是除了包括它作为一个编译时间依赖;

  {相关性
    贴切com.jakewharton:奶油刀:$ {} butterknifeVersion    编译com.jakewharton:奶油刀:$ {} butterknifeVersion
}

I had my project working great with Butterknife to do view injection. But I then needed to add Dagger in order to inject dependencies.

I added the Annotation Processor Tool Gradle plugin with the appropriate Dagger requirement (Only showing the modified parts for brevity);

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'

dependencies {
    apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"

    ...
}

At this point now when I build and run the application the properties marked with the @InjectView annotation are not getting injected with the following debug messages emitted by Butterknife;

D/ButterKnife﹕ Looking up view injector for com.example.MainActivity
D/ButterKnife﹕ Not found. Trying superclass com.example.FactListAbstractActivity
D/ButterKnife﹕ Not found. Trying superclass android.app.Activity

解决方案

Turns out all I needed to do was add another apt dependency in order to have the Annotation Processor Tool pickup the processor included in Butterknife. This is in addition to including it as a compile time dependency;

dependency {
    apt "com.jakewharton:butterknife:${butterknifeVersion}"

    compile "com.jakewharton:butterknife:${butterknifeVersion}"
}

这篇关于我如何获得匕首和奶油刀与摇篮工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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