匕首2和android工作室:工作,但无法看到生成的类 [英] Dagger 2 and android Studio: working but can't see generated classes

查看:219
本文介绍了匕首2和android工作室:工作,但无法看到生成的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用匕首2在Android Studio项目。我用咖啡机的例子。我已经成功地使应用程序的构建和工作然而: - 我没有成功,眼看着产生code。 - 如果我调试,我还看不出来两者都不是。 - 此外DaggerCoffeeApp_Coffee作为标记为芦苇(无法解析符号)

I'm trying to use Dagger 2 in an Android Studio Project. I've used the CoffeeMaker example. I've managed to make the app build and working however: - I don't success in seeing the generated code. - If I debug, I can't see it neither. - Moreover DaggerCoffeeApp_Coffee as marked as reed (Cannot resolve symbol)

我的摇篮文件是:

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'

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

allprojects {
    repositories {
        jcenter()
    }
}

apply plugin: 'com.android.application'


android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.mateuyabar.android.dagger2test"
        minSdkVersion 22
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false // ignoring some references from dagger-compiler
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'javax.inject:javax.inject:1'
    compile 'javax.annotation:javax.annotation-api:1.2'
    compile 'com.google.dagger:dagger:2.0'
    provided 'com.google.dagger:dagger-compiler:2.0'
    provided 'org.glassfish:javax.annotation:10.0-b28'

}

感谢

推荐答案

使用 Android的公寓插件通过雨果·维瑟

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

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    // the latest version of the android-apt plugin
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
  }
}

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.mateuyabar.android.dagger2test"
        minSdkVersion 22
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false // ignoring some references from dagger-compiler
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'javax.inject:javax.inject:1'
    compile 'javax.annotation:javax.annotation-api:1.2'
    compile 'com.google.dagger:dagger:2.0'
    apt 'com.google.dagger:dagger-compiler:2.0'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}

注意易com.google.dagger:匕首编译:2.0 行也是如此。这应该使对作为生成的源可见。

Note the apt 'com.google.dagger:dagger-compiler:2.0' line as well. This should make the generated sources visible for AS.

这篇关于匕首2和android工作室:工作,但无法看到生成的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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