:运行单元测试时出现app:kaptDebugKotlin错误

我一直在尝试Kotlin和实施一个应用程序。 目前运行该应用程序工作正常,但我不能运行单元测试。

Android Studio:2.3.3

这是我的Gradle设置:

的build.gradle(项目)

buildscript { ext.kotlin_version = '1.1.3' repositories { jcenter() maven { url 'https://jitpack.io' } } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" classpath "io.realm:realm-gradle-plugin:3.5.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } 

的build.gradle(模块)

 apply plugin: 'com.android.application' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'realm-android' android { compileSdkVersion 25 buildToolsVersion "25.0.1" defaultConfig { applicationId "com.example.myapp" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } sourceSets { main.java.srcDirs += 'src/main/kotlin' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kapt { generateStubs = true } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' compile group: 'com.google.code.gson', name: 'gson', version:'2.8.0' androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:3.3.2' } repositories { mavenCentral() } class FileUtils(assets: AssetManager) { val assets = assets fun <T> readJsonFromAsset(fileName: String, tClass: Class<T>): T { val text: String? = this.assets.open(fileName)?.bufferedReader()?.readText(); val typeToken = object : TypeToken<T>() {}.type val gson: Gson = Gson() return gson.fromJson<T>(text, typeToken) } } @RunWith(RobolectricTestRunner::class) @Config(constants = BuildConfig::class) class FileUtilsTest { val fileUtils: FileUtils init { val assetManager = Robolectric.buildActivity(Activity::class.java).create().get().assets fileUtils = FileUtils(assetManager) } @Test fun readJsonFromAsset_ShouldGetQuestionList() { val questions = fileUtils.readJsonFromAsset("part1.json", Questions::class.java) assert(7 == questions.size) } class Questions : ArrayList<Question>() } 

错误信息:

 Information:Gradle tasks [:app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:compileDebugUnitTestSources] Error:Execution failed for task ':app:kaptDebugKotlin'. > Internal compiler error. See log for more details 

我曾经尝试过:

 Tried with kotlin_version from 1.1.1 to 1.1.3 Tried with compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" Clean Project Clean cache and restart Android Studio 

我认为Kotlin不能顺利地运行一些库,而且需要努力修复它。 如果我不能使用Kotlin比Java更容易进行单元测试,那么我不想使用Kotlin,但是想要做更多的实验。 我会感激你的帮助。