无法使用dialogflow完成构建gradle [英] Cannot complete build gradle with dialogflow

查看:112
本文介绍了无法使用dialogflow完成构建gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Android应用中使用最新版本的对话框。但是,当我将其集成到应用gradle中时,出现以下构建错误:

I'd like to use the latest version of dialog-flow in my Android app. However when I integrate it in my app gradle, I get the following build error:


任务‘:app:mergeDebugJavaResource’的执行失败。
执行com.android.build.gradle.internal.tasks.Workers $ ActionFacade
时发生故障,发现多个文件与OS无关,路径为'META-INF / INDEX.LIST'

Execution failed for task ':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'

为了缩小错误,我在一个测试项目中将build gradle依赖性最小化为:

In order to narrow down the bug, I minimized my build gradle dependencies in a test project to:

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'
}

我仍然遇到相同的错误,但至少我知道该错误不是由我的任何其他依赖关系引起的在我的实际项目中。
在搜索了相关的论坛问题之后,我尝试了许多解决方案建议,例如向我的构建gradle添加PackagingOptions:

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 {
        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'
    }

并从我的dialogflow实现中排除组:

and to exclude groups from my dialogflow implementation:

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

最后一个解决方案建议实际上有帮助我来构建gradle,但是由于dialogflow库基于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.

我也尝试过使用0.120.2之类的旧版本,只会导致相同的问题。

I've also tried to use older versions like 0.120.2, resulting only in the same issue.

你们中的某个人已经解决了这个问题吗?我也愿意使用其他库与dialogflow代理进行通信。
对我来说,使用最新的API v2访问对话流(我已经有一些使用v1的项目)对我来说很重要,因为v1将很快被弃用。

Has someone of you solved this issue already? I'm also open to use a different library to communicate with my dialogflow agent. 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.

非常感谢您的帮助!

推荐答案

最后我找到了解决方法,所以我没有必须使用dialogflow客户端库。
对于身份验证,我使用

In the end I found a workaround, so I don't have to use the dialogflow client library. 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"));

文件文件是我从Google ServiceAccount中检索到的JSON文件/密钥,已分配给我对话流代理。
使用凭据,我可以检索访问令牌:

File file is the JSON file/key that I retrieved from my Google ServiceAccount, which is assigned to my dialogflow agent. 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;
}

借助此令牌,我可以建立HTTPURLConnection并将请求发送给我对话流代理:

With the help of this token I can establish a HTTPURLConnection and send requests to my dialogflow agent:

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

我希望这会帮助其他想要使用dialogflow v2 API的Android开发人员!

I hope, this will help other Android developers, who want to use the dialogflow v2 API!

欢呼声

这篇关于无法使用dialogflow完成构建gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆