-1
我有一個使用此結構的項目:https://github.com/android10/Android-CleanArchitecture,我試圖將它轉換爲Kotlin。使用純Kotlin模塊的類時,Android庫模塊無法編譯
結構域模塊編譯就好了,但是當我嘗試編譯數據模塊我得到以下錯誤:
Unresolved reference: ThreadExecutor`
和其他一些類似的錯誤。
這些錯誤是關於接口,dataclass或Dagger單例。看起來數據模塊無法從域模塊中找到一些對象(儘管IntelliJ在編輯器中沒有顯示任何錯誤)。
這裏是ThreadExecutor接口:
package com.company.app.domain.executor
import java.util.concurrent.Executor
interface ThreadExecutor : Executor
結構域模塊的build.gradle文件:
apply plugin: 'java'
apply plugin: 'kotlin'
//noinspection GroovyUnusedAssignment
sourceCompatibility = JavaVersion.VERSION_1_7
//noinspection GroovyUnusedAssignment
targetCompatibility = JavaVersion.VERSION_1_7
buildscript {
repositories {
mavenCentral()
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
compile 'io.reactivex.rxjava2:rxkotlin:2.1.0'
compile 'com.google.guava:guava:22.0-android'
compile 'javax.inject:javax.inject:1'
compile 'joda-time:joda-time:2.9.9'
}
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}
全球項目的build.gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'kotlin'
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
}
clean {
delete rootProject.buildDir
}
最後的數據模塊build.gralde:
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
publishNonDefault true
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile project(':domain')
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
compile 'io.reactivex.rxjava2:rxkotlin:2.1.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
kapt 'com.google.dagger:dagger-compiler:2.11'
compile 'com.google.dagger:dagger:2.11'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
它看起來像從Kotlin編譯的域jar不會以數據模塊期望的方式暴露這些對象,但我目前不知道爲什麼。