使用纯Kotlin模块中的类时,Android库模块无法编译

时间:2017-09-23 14:00:38

标签: android kotlin

我有一个使用此结构的项目: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看起来不像数据模块所期望的那样暴露这些对象,但我目前还不知道为什么。

1 个答案:

答案 0 :(得分:0)

我终于找到了为什么它没有编译:我不得不调用“rebuild project”而不是“make project”,以便Android Studio考虑所有的变化。