Android Studio 3.0 未解决的参考:SupportedLanguages for AIConfiguration class in Dialogflow(api.ai)

Android Studio 3.0 Unresolved reference: SupportedLanguages for AIConfiguration class in Dialogflow(api.ai)

我正在通过对 Dialogflow 代理的查询在 Kotlin 中构建一个聊天机器人 Android 应用程序。我正在使用该存储库中提供的 Dialogflow android client github repository Readme and the sample app 作为构建应用程序的基础。如上述来源所述,AIConfiguration.SupportedLanguages 的 java 代码工作正常:

import ai.api.android.AIConfiguration;
.....
private void initService(final LanguageConfig selectedLanguage) {
final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode());
.....

您可以找到此 here 的完整用法。

当我在 Kotlin 中实现它时:

import ai.api.android.AIConfiguration
....
    private fun initService() {
        //final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode());
        val config = AIConfiguration(CLIENT_ACCESS_TOKEN,
                AIConfiguration.SupportedLanguages.EnglishGB,
                AIConfiguration.RecognitionEngine.System)
....

在 Android 3.0 中,我收到 AIConfiguration.SupportedLanguages 的 gradle 错误“未解决的参考:SupportedLanguages”。 AIConfiguration.RecognitionEngine 解决得很好。为什么会出现这个问题?我可以实现什么solution/work-around?

我的更高级别build.gradle 文件:

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 27
    baseFeature true
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '27.0.1'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    api 'com.android.support:appcompat-v7:27.0.0'
    api 'com.android.support:design:27.0.0'
    api 'com.android.support.constraint:constraint-layout:1.0.2'

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'ai.api:sdk:2.0.7@aar'
    compile 'ai.api:libai:1.6.12'
    //compile project(':ailib')

    application project(':app')
    feature project(':chatbot')
}

我的模块build.gradle 文件:

apply plugin: 'com.android.feature'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '27.0.1'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    implementation project(':base')

    //add the google gson library
    compile 'com.google.code.gson:gson:2.8.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}

我发现一个可行的解决方法是使用正在解析的 ai.api.AIConfiguration.SupportedLanguages 而不是问题中提到的 Android Studio 3.0 中未在 kotlin 中解析的 ai.api.android.AIConfiguration.SupportedLanguages

但是,调用 ai.api.android.AIConfiguration.SupportedLanguages 在 Java 代码中工作得很好,在这种情况下它在 Android Studio 3.0 中正确解析。既然ai.api.android.AIConfiguration实现了ai.api.AIConfiguration,为什么会出现这个问题呢!

只需使用这一行而不是之前的 -

ai.api.AIConfiguration.SupportedLanguages.English,