2017-11-20 10 views
0

私はDialogflowエージェントへのクエリを通じて、Kotlinでchatbot Androidアプリを構築しています。私はDialogflow android client github repository Readmeとそのリポジトリで提供されているsample appを使ってアプリケーションを構築しています。上記のソースで言及されているように、AIConfiguration.SupportedLanguagesのためのJavaコードは正常に動作します:Androidスタジオ3.0未解決のリファレンス:Dialogflow(api.ai)のAIConfigurationクラスのサポートされている言語

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

あなたはこのhereの完全な使用を見つけることができます。

私はKotlinでこれを実装しています:アンドロイド3.0で

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) 
.... 

私はGradleのエラー取得しています:AIConfiguration.SupportedLanguagesための "未解決の参照SupportedLanguagesを"。 AIConfiguration.RecognitionEngineはうまく解決しています。なぜこの問題が起こっているのですか?どのような解決策/回避策を実装できますか?

私のより高いレベル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:[email protected]' 
    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' 

} 
+0

Javaで 'ai.api.android.AIConfiguration.SupportedLanguages'を呼び出すと上のようにうまく動作します。上記のコードで見つけたKotlin 1の解決策では、正しく解決されたコードで 'ai.api.AIConfiguration.SupportedLanguages'を使用することです。しかし、 'ai.api.android.AIConfiguration'は' ai.api.AIConfiguration'を実装しています。それでなぜこの問題が発生するのか分かりません。 –

答えて

0

回避策の一つが解決されていない代わりにai.api.android.AIConfiguration.SupportedLanguagesの解決されai.api.AIConfiguration.SupportedLanguagesを使用することですAndroid Studio 3.0のkotlinの質問に記載されています。

ただし、ai.api.android.AIConfiguration.SupportedLanguagesを呼び出すとJavaコードが正常に動作します。この場合、Androidスタジオ3.0では正しく解決されます。 ai.api.android.AIConfigurationai.api.AIConfigurationを実装しているので、なぜこの問題が発生しているのかは不思議です!