简体   繁体   English

无法使用 dialogflow 完成构建 gradle

[英]Cannot complete build gradle with dialogflow

I'd like to use the latest version of dialog-flow in my Android app.我想在我的 Android 应用程序中使用最新版本的对话流。 However when I integrate it in my app gradle, I get the following build error:但是,当我将它集成到我的应用程序 gradle 中时,出现以下构建错误:

Execution failed for task ':app:mergeDebugJavaResource'.任务“:app:mergeDebugJavaResource”执行失败。 A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade More than one file was found with OS independent path 'META-INF/INDEX.LIST'执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障 发现多个文件与操作系统无关的路径 'META-INF/INDEX.LIST'

In order to narrow down the bug, I minimized my build gradle dependencies in a test project to:为了缩小错误的范围,我将测试项目中的构建 gradle 依赖项最小化为:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.cloud:google-cloud-dialogflow:1.0.0'
}

I still get the same error, but at least I know that the bug is not caused by any other dependencies I have in my actual project.我仍然遇到相同的错误,但至少我知道该错误不是由我在实际项目中的任何其他依赖项引起的。 After searching through related forum questions, I tried many solution proposals like adding packagingOptions to my build gradle:在搜索了相关的论坛问题后,我尝试了许多解决方案,例如将 PackagingOptions 添加到我的构建 gradle 中:

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

and to exclude groups from my dialogflow implementation:并从我的对话流实现中排除组:

implementation('com.google.cloud:google-cloud-dialogflow:1.0.0'){
        exclude group: 'com.google.api.grpc'
}

The last solution proposal actually helps me to build my gradle, however as the dialogflow lib is based on grpc, most of the classes are not available anymore, which turns the whole lib quite useless for me.最后一个解决方案提案实际上帮助我构建了我的 gradle,但是由于 dialogflow 库基于 grpc,大多数类不再可用,这使得整个库对我来说毫无用处。

I've also tried to use older versions like 0.120.2, resulting only in the same issue.我也试过使用像 0.120.2 这样的旧版本,结果只是出现了同样的问题。

Has someone of you solved this issue already?你们中有人已经解决了这个问题吗? I'm also open to use a different library to communicate with my dialogflow agent.我也愿意使用不同的库与我的 dialogflow 代理进行通信。 For me it is just important to use the latest API v2 to access dialogflow (I have already some working projects with v1), as v1 will be deprecated very soon.对我来说,使用最新的 API v2 来访问 dialogflow 很重要(我已经有一些使用 v1 的工作项目),因为 v1 很快就会被弃用。

Thanks a lot in advance for your help!非常感谢您的帮助!

In the end I found a workaround, so I don't have to use the dialogflow client library.最后我找到了一个解决方法,所以我不必使用 dialogflow 客户端库。 For the authentication I use对于我使用的身份验证

implementation 'com.google.apis:google-api-services-oauth2:v2-rev99-1.21.0'

so I can create my credentials:所以我可以创建我的凭据:

GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream(file)).createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/dialogflow"));

File file is the JSON file/key that I retrieved from my Google ServiceAccount, which is assigned to my dialogflow agent.文件文件是我从我的 Google ServiceAccount 中检索到的 JSON 文件/密钥,它被分配给我的对话流代理。 With the credential I can retrieve my access token:使用凭证,我可以检索我的访问令牌:

private String getToken(){
    try {
        credential.refreshToken();
        return credential.getAccessToken();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

With the help of this token I can establish a HTTPURLConnection and send requests to my dialogflow agent:在这个令牌的帮助下,我可以建立一个 HTTPURLConnection 并向我的对话流代理发送请求:

URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
String token = getToken();
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.setRequestProperty("Accept", "application/json");
connection.connect()
...

I hope, this will help other Android developers, who want to use the dialogflow v2 API!我希望,这将有助于其他想要使用 dialogflow v2 API 的 Android 开发人员!

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM