如何将 Kotlin 文件添加到旧 android java 项目?

How to add a Kotlin file to old android java projects?

我正在尝试构建一个基于 ODK Collect 的 android 应用程序。 ODK Collect 应用程序是用 Java 编写的。我想使用 Kotlin 进行开发。我使用 android studio new activity 向导添加了一个基于 Kotlin 的空 activity。当我尝试编译时出现以下错误;

Executing tasks: [:collect_app:assembleDebug]


> Configure project :collect_app
Could not find google-services.json while looking in [src/nullnull/odkCollectRelease, src/odkCollectRelease/nullnull, src/nullnull, src/odkCollectRelease, src/nullnullOdkCollectRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
collect_app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.google.dagger:dagger-android-processor:2.16', 'com.google.dagger:dagger-compiler:2.16', 'com.jakewharton:butterknife-compiler:8.8.1', 'com.google.dagger:dagger-compiler:2.16'.
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin
'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin

> Task :collect_app:preBuild UP-TO-DATE
> Task :collect_app:preDebugBuild UP-TO-DATE
> Task :collect_app:compileDebugAidl UP-TO-DATE
> Task :collect_app:compileDebugRenderscript UP-TO-DATE
> Task :collect_app:checkDebugManifest UP-TO-DATE
> Task :collect_app:generateDebugBuildConfig UP-TO-DATE
> Task :collect_app:mainApkListPersistenceDebug UP-TO-DATE
> Task :collect_app:mergeDebugShaders UP-TO-DATE
> Task :collect_app:compileDebugShaders UP-TO-DATE
> Task :collect_app:generateDebugAssets UP-TO-DATE
> Task :collect_app:mergeDebugAssets UP-TO-DATE

> Task :collect_app:processDebugGoogleServices
Parsing json file: C:\Users\Santosh\Desktop\collect\collect_app\src\debug\google-services.json

> Task :collect_app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :collect_app:processDebugManifest
> Task :collect_app:fabricGenerateResourcesDebug
> Task :collect_app:generateDebugResValues UP-TO-DATE
> Task :collect_app:generateDebugResources UP-TO-DATE
> Task :collect_app:mergeDebugResources
> Task :collect_app:splitsDiscoveryTaskDebug UP-TO-DATE
> Task :collect_app:processDebugResources
e: java.util.ServiceConfigurationError: org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar: Provider org.jetbrains.kotlin.android.synthetic.AndroidComponentRegistrar not a subtype
    at java.util.ServiceLoader.fail(ServiceLoader.java:239)
    at java.util.ServiceLoader.access0(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader.next(ServiceLoader.java:480)
    at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1132)
    at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1165)
    at org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser.loadPlugins(PluginCliParser.kt:70)
    at org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser.loadPluginsSafe(PluginCliParser.kt:45)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.loadPlugins(K2JVMCompiler.kt:267)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:77)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:362)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:225)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile.invoke(IncrementalCompilerRunner.kt:91)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:103)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:606)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:455)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:1029)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1071)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1028)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:454)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
    at sun.rmi.transport.Transport.run(Transport.java:200)
    at sun.rmi.transport.Transport.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run[=12=](TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

> Task :collect_app:kaptGenerateStubsDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':collect_app:kaptGenerateStubsDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 19s
18 actionable tasks: 6 executed, 12 up-to-date

ODK 收集应用程序: https://github.com/opendatakit/collect

顶级build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.3.0'

    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.0.1'         
        classpath 'org.ow2.asm:asm:6.0' // https://github.com/jacoco/jacoco/issues/639#issuecomment-355424756
        classpath 'org.jacoco:org.jacoco.core:0.8.0'
        classpath 'io.fabric.tools:gradle:1.26.1'
    }
}

plugins {
    id 'com.github.spotbugs' version '1.6.2'
}

allprojects {
    repositories {
        // Needs to go first to get specialty libraries 
        google()

        jcenter()
        maven { url 'https://oss.sonatype.org/content/groups/public' }
        maven { url 'https://jitpack.io' }
        maven { url 'https://staging.dev.medicmobile.org/_couch/maven-repo' }
    }
}

configurations.all {
    transitive = true
}

task checkAll(type: GradleBuild) {
    tasks = ['checkCode', 'checkTests']
}

task checkCode(type: GradleBuild) {
    tasks = ['pmd', 'checkstyle', 'lintDebug', 'spotbugsDebug']
}

task checkTests(type: GradleBuild) {
    tasks = ['testDebugUnitTest', 'connectedDebugAndroidTest']
}

ext {
    supportLibraryVersion = '28.0.0'
    leakyCanaryVersion = '1.5.4'
    daggerVersion = '2.16'
    rxLifecycleVersion = '2.2.1'
    workManagerVersion = "1.0.0-alpha10"
}

应用build.gradle;

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: '../config/quality.gradle'
apply from: '../config/jacoco.gradle'

import com.android.ddmlib.DdmPreferences

DdmPreferences.setTimeOut(60000)

ant.condition(property: 'os', value: 'windows') {
    os(family: 'windows')
}
ant.condition(property: 'os', value: 'unix') {
    os(family: 'unix')
}

// Build numbers were manually set until 1067
def LEGACY_BUILD_NUMBER_OFFSET = 1067

// Based on 
def getMasterCommitCount = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            switch (ant.properties.os) {
                case 'windows':
                    commandLine 'cmd', '/c', 'git', 'rev-list', '--first-parent', '--count', 'master'
                    break
                case 'unix':
                    commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
                    break
            }
            standardOutput = stdout
        }
        return Integer.parseInt(stdout.toString().trim())
    } catch (ignored) {
        return -1
    }
}

def getVersionName = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            switch (ant.properties.os) {
                case 'windows':
                    commandLine 'cmd', '/c', 'git', 'describe', '--tags', '--dirty', '--always'
                    break
                case 'unix':
                    commandLine 'git', 'describe', '--tags', '--dirty', '--always'
                    break
            }
            standardOutput = stdout
        }
        return stdout.toString().trim()
    } catch (ignored) {
        return null
    }
}

def secretsFile = file('secrets.properties')
def secrets = new Properties()
if (secretsFile.exists()) {
    secrets.load(new FileInputStream(secretsFile))
}

android {
    compileSdkVersion(28)

    defaultConfig {
        applicationId('org.odk.collect.android')
        minSdkVersion(16)
        targetSdkVersion(28)
        versionCode LEGACY_BUILD_NUMBER_OFFSET + getMasterCommitCount()
        versionName getVersionName()
        testInstrumentationRunner('android.support.test.runner.AndroidJUnitRunner')
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        archivesBaseName = 'collect'
    }

    signingConfigs {
        release {
            if (secrets.getProperty('RELEASE_STORE_FILE')) {
                storeFile file(secrets.getProperty('RELEASE_STORE_FILE'))
                storePassword secrets.getProperty('RELEASE_STORE_PASSWORD')
                keyAlias secrets.getProperty('RELEASE_KEY_ALIAS')
                keyPassword secrets.getProperty('RELEASE_KEY_PASSWORD')
            }
        }
    }

    buildTypes {
        // Release build for all forks
        release {
            if (secrets.getProperty('RELEASE_STORE_FILE')) {
                signingConfig signingConfigs.release
            }
            minifyEnabled(true)
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            resValue("bool", "FIREBASE_CRASHLYTICS_ENABLED", "false")
        }
        // Release build for the original ODK Collect app
        odkCollectRelease {
            if (secrets.getProperty('RELEASE_STORE_FILE')) {
                signingConfig signingConfigs.release
            }
            minifyEnabled(true)
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            resValue("bool", "FIREBASE_CRASHLYTICS_ENABLED", "true")
        }
        debug {
            debuggable(true)
            testCoverageEnabled(true)
            resValue("bool", "FIREBASE_CRASHLYTICS_ENABLED", "false")
        }
    }

    // 
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = new File(outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk"))
        }
    }
    testVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = new File(outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk"))
        }
    }

    packagingOptions {
        // Pick first occurrence of any files that cause conflicts, as defined
        // in common.gradle
        pickFirst 'META-INF/DEPENDENCIES'
        pickFirst 'META-INF/LICENSE'
        pickFirst 'META-INF/LICENSE.txt'
        pickFirst 'META-INF/NOTICE'
        pickFirst 'META-INF/NOTICE.txt'
        pickFirst 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
        pickFirst 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
        pickFirst 'META-INF/services/javax.ws.rs.ext.MessageBodyReader'
        pickFirst 'META-INF/services/javax.ws.rs.ext.MessageBodyWriter'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize '2048M'
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
            returnDefaultValues = true
            all {
                // https://discuss.circleci.com/t/11207/24
                // it seems any number works, but 1024 - 2048 seem reasonable
                maxHeapSize = "2048M"
            }
        }
    }
}

configurations.all {
    resolutionStrategy {
        cacheDynamicVersionsFor(0, 'seconds')
        cacheChangingModulesFor(0, 'seconds')

        force('com.google.code.findbugs:jsr305:1.3.9')
    }
    transitive = true
}

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << '-Xlint:all'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    implementation "com.android.support:support-v13:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:customtabs:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:design:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:appcompat-v7:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:design:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:cardview-v7:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:exifinterface:${rootProject.supportLibraryVersion}"
    implementation "com.android.support:multidex:1.0.3"

    implementation "com.google.android.gms:play-services-analytics:16.0.4"
    implementation "com.google.android.gms:play-services-auth:16.0.1"
    implementation "com.google.android.gms:play-services-maps:16.0.0"
    implementation "com.google.android.gms:play-services-location:16.0.0"

    implementation "com.google.firebase:firebase-core:16.0.4"
    implementation "com.crashlytics.sdk.android:crashlytics:2.9.5"

    implementation("com.google.guava:guava:26.0-android")

    implementation("com.google.code.gson:gson:2.6.2") {
        exclude group: 'org.apache.httpcomponents'
    }

    implementation("com.google.http-client:google-http-client:1.22.0") {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation("com.google.oauth-client:google-oauth-client:1.22.0") {
        exclude group: 'org.apache.httpcomponents'
    }

    implementation 'bikramsambat:bikram-sambat:1.0.0'
    implementation "com.evernote:android-job:1.2.5"
    implementation "com.rarepebble:colorpicker:2.3.1"
    implementation "commons-io:commons-io:2.6"
    implementation "net.sf.kxml:kxml2:2.3.0"
    implementation "net.sf.opencsv:opencsv:2.3"
    implementation("org.opendatakit:opendatakit-javarosa:2.12.0") {
        exclude group: 'joda-time'
        exclude group: 'org.slf4j'
    }
    implementation "com.karumi:dexter:4.2.0"
    implementation "org.osmdroid:osmdroid-android:5.6.4"
    implementation "org.slf4j:slf4j-android:1.6.1-RC1"
    implementation("com.google.api-client:google-api-client-android:1.22.0") {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.google.guava'
    }
    implementation("com.google.apis:google-api-services-drive:v3-rev64-1.22.0") {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.google.guava'
    }
    implementation("com.google.apis:google-api-services-sheets:v4-rev463-1.22.0") {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.google.guava'

    }
    implementation "com.jakewharton.timber:timber:4.7.0"
    implementation "com.google.zxing:core:3.3.0"
    implementation "com.journeyapps:zxing-android-embedded:3.5.0"
    implementation "net.danlew:android.joda:2.9.9"

    // Real LeakCanary for debug builds only: notifications, analysis, etc
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.leakyCanaryVersion}"
    // No-Op version of LeakCanary for release builds: no notifications, no analysis, nothing
    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakyCanaryVersion}"
    testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakyCanaryVersion}"
    androidTestImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakyCanaryVersion}"
    odkCollectReleaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.leakyCanaryVersion}"

    // Android Architecture Components:
    implementation "android.arch.lifecycle:extensions:1.1.1"

    // Dagger:
    implementation "com.google.dagger:dagger-android:${rootProject.daggerVersion}"
    implementation "com.google.dagger:dagger-android-support:${rootProject.daggerVersion}"
    annotationProcessor "com.google.dagger:dagger-android-processor:${rootProject.daggerVersion}"
    annotationProcessor "com.google.dagger:dagger-compiler:${rootProject.daggerVersion}"
    testAnnotationProcessor "com.google.dagger:dagger-compiler:${rootProject.daggerVersion}"

    // RxJava 2:
    implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
    implementation "io.reactivex.rxjava2:rxjava:2.1.10"

    // Better "Subjects" for Rx:
    implementation "com.jakewharton.rxrelay2:rxrelay:2.0.0"

    // Android bindings for Rx:
    implementation "com.jakewharton.rxbinding2:rxbinding:2.0.0"

    // RxLifecycle (binds subscription cleanup to component lifecycle):
    implementation "com.trello.rxlifecycle2:rxlifecycle:${rootProject.rxLifecycleVersion}"
    implementation "com.trello.rxlifecycle2:rxlifecycle-android:${rootProject.rxLifecycleVersion}"
    implementation "com.trello.rxlifecycle2:rxlifecycle-android-lifecycle:${rootProject.rxLifecycleVersion}"

    // WorkManager for specifying deferrable, asynchronous tasks
    implementation("android.arch.work:work-runtime:${rootProject.workManagerVersion}") {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    // Optional JobDispatcher support so devices with Play Services do better than AlarmManager
    implementation("android.arch.work:work-firebase:${rootProject.workManagerVersion}") {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }

    // Makes binding to Views easy:
    implementation "com.jakewharton:butterknife:8.8.1"
    annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"

    // Annotations understood by FindBugs
    compileOnly 'com.google.code.findbugs:annotations:3.0.1'
    compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

    // Used to generate documentation screenshots.
    androidTestImplementation "tools.fastlane:screengrab:1.1.0"

    // Testing-only dependencies
    testImplementation "junit:junit:4.12"
    testImplementation "org.mockito:mockito-core:2.8.47"
    testImplementation "org.robolectric:robolectric:4.0-beta-1"
    testImplementation "org.robolectric:shadows-multidex:4.0-beta-1"

    // power mock (for mocking final methods which is not handled by mockito)
    testImplementation "org.powermock:powermock-module-junit4:1.6.4"
    testImplementation "org.powermock:powermock-api-mockito2:1.7.3"

    androidTestImplementation "org.mockito:mockito-android:2.11.0"
    androidTestImplementation("com.android.support.test:runner:1.0.1") {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs', module: 'jsr305'
    }

    androidTestImplementation("com.android.support.test.espresso:espresso-intents:3.0.1") {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs', module: 'jsr305'
    }

    androidTestImplementation "com.squareup.okhttp3:mockwebserver:3.9.0"

    androidTestImplementation "android.arch.work:work-testing:${rootProject.workManagerVersion}"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

// Must be at bottom to prevent dependency collisions
// https://developers.google.com/android/guides/google-services-plugin
apply plugin: 'com.google.gms.google-services'

编辑:Activity Kotlin

package org.odk.collect.android.activities

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import org.odk.collect.android.R

class LoginActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
    }
}

我没有向 gradle 添加必要的 Kotlin 配置吗?我该如何解决这个问题?

这里有一些尝试重建的东西。让我知道进展如何。

尝试点击工具菜单 -> Kotlin -> 在项目中配置 Kotlin。

尝试点击工具菜单 -> Kotlin -> 配置 Kotlin 插件更新

尝试添加

apply plugin: 'kotlin-kapt'

尝试单击“文件”->“无效”caches/restart

更新 添加到 build.gradle

kapt { generateStubs = true }

此问题已在 Kotlin 版本 1.3.20 中修复。