使用纯Kotlin模块的类时,Android库模块不会编译



我有一个使用此结构的项目:https://github.com/android10/android-cleanarchitecture,我正在尝试将其转换为Kotlin。

域模块可以很好地编译,但是当我尝试编译数据模块时,我会收到以下错误:

Unresolved reference: ThreadExecutor`

和其他一些类似的错误。

这些错误是关于接口,数据级或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并没有按照数据模块的期望来公开这些对象,但是我目前毫无头绪。

我终于找到了为什么没有编译:我不得不称呼"重建项目",而不是"制作项目",以使Android Studio考虑所有更改。

最新更新