如何使“提供”范围在Android Studio上运行?

时间:2016-02-26 07:57:03

标签: java android gradle provider dagger

如何让“提供”范围适用于Android Studio上的dagger? 运行我的项目后,我遇到了这个问题: Module adapter for class com.example.Module could not be loaded. Please ensure that code generation was run for this module.

我的gradle在

之下
 buildscript {
        repositories {
            mavenCentral()
        }
    }
apply plugin: 'com.android.application'

configurations {
    provided
}

android {
    buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
            debuggable false
        }

    }

    sourceSets {
        main {
            java.srcDirs = ['/src/main/java']
            res.srcDirs = ['/src/main/res']
            assets.srcDirs = ['/src/main/assets']
            compileClasspath += [configurations.provided]//it doesn work, Error: Could not find property 'compileClasspath' on source set main.
        }
    }


}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.squareup.dagger:dagger:1.2.2'
    provided 'com.squareup.dagger:dagger-compiler:1.2.2'
}

Top gradle:

// 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:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

1 个答案:

答案 0 :(得分:1)

compileClasspath无效的原因是因为Gradle的Android插件使用自己的源集:https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.api.AndroidSourceSet.html

顺便说一下,Gradle的Android插件还会创建一个provided配置,因此您不必配置任何内容。

话虽这么说,您应该使用android-apt插件及其apt配置,而不是provided配置:https://bitbucket.org/hvisser/android-apt(请参阅自述文件中的Q / A为什么你更喜欢aptprovided