我正在和Kotlin在一个Android项目中测试"dagger 2".我受到了Android Clean Architecture回购的启发.我的Gradle版本中有两个模块,一个是"app",另一个是"module".模块包含一个类调用模型.在我的app Gradle模块中,我使用Model提供程序创建了一个名为"DaggerModule"的dagger 模块.当我try 构建项目时,收到编译错误:
DaggerModule.kt: (3, 57): Unresolved reference: Model
DaggerModule.kt: (9, 34): Unresolved reference: Model
DaggerModule.kt: (9, 42): Unresolved reference: Model
When I try moving the Model class from "module" module to inside of the "app" module everything compiles w/o error. Trying to figure out if I'm doing something stupid, or if I should file a bug somewhere.
此处提供有问题文件的片段以供参考:
----
app/build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.1218'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
repositories {
jcenter()
mavenCentral()
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.github.app.kotlin_unresolved_reference.app"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':module')
compile 'com.android.support:appcompat-v7:22.2.1'
kapt "com.google.dagger:dagger-compiler:2.0.1"
compile "com.google.dagger:dagger:2.0.1"
compile "javax.annotation:javax.annotation-api:1.2"
compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.1218"
}
---
module/build.gradle
apply plugin: 'java'
//noinspection GroovyUnusedAssignment
sourceCompatibility = 1.7
//noinspection GroovyUnusedAssignment
targetCompatibility = 1.7
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}
dependencies {
provided "com.google.dagger:dagger-compiler:2.0.1"
compile "com.google.dagger:dagger:2.0.1"
compile "javax.annotation:javax.annotation-api:1.2"
compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.1218"
}
---
DaggerModule.kt
Module
public class DaggerModule {
Provides fun provideModel(): Model = Model()
}
----
Model.kt
public class Model { }
免责声明:这是我第一次试驾dagger 2,我是一个新手.示例项目是我能找到的显示问题的最少代码.我并不指望它能起到多大作用.