2017-09-23 91 views
-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不会以数据模块期望的方式暴露这些对象,但我目前不知道为什么。

回答

0

我终于找到了它为什么不编译的原因:为了让Android Studio将所有更改考虑在内,我不得不调用“重建项目”而不是“make project”。