无法在 Android 中导入 com.google.cloud.speech.v1.SpeechGrpc

2024-01-07

我正在尝试使用谷歌的语音API https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech在Android项目中。示例项目有效。我在我自己的 Android 应用程序中使用它时遇到问题。

build.gradle(模块:应用程序):

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

ext {
    supportLibraryVersion = '25.4.0'
    grpcVersion = '1.4.0'
}
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "ApplicationID"
        minSdkVersion 16
        targetSdkVersion 24
//        compileOptions {
//            sourceCompatibility JavaVersion.VERSION_1_5
//            targetCompatibility JavaVersion.VERSION_1_5
//        }
    }
    signingConfigs {
        release {
            storeFile file(project.properties.storeFile)
            storePassword project.properties.storePassword
            keyAlias project.properties.keyAlias
            keyPassword project.properties.keyPassword
        }
    }
    productFlavors {
        dev {
            // Minimum version with platform multi-dex support
            minSdkVersion 21
        }
        prod {
            // Minimum version that can run gRPC (TLS extension)
            minSdkVersion 16
        }
    }
    buildTypes {
        debug {
            minifyEnabled false
            multiDexEnabled true
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
    }
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

//
//        buildTypes {
//        release {
//            minifyEnabled false
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
//        }
//    }
//    compileOptions {
//        targetCompatibility 1.6
//        sourceCompatibility 1.6
//    }
//}

dependencies {
    //    compile 'com.android.support:support-v4:18.0.0'
    //    compile 'com.android.support:appcompat-v7:24.2.1'
//    compile 'com.google.apis:google-api-services-speech:v1-rev8-1.22.0'
    compile group: 'com.google.cloud', name: 'google-cloud-speech', version: '0.17.1-alpha'
//    compile 'com.google.android.gms:play-services:11.0.2'
    compile project(':lib')    //This is someother library I'm using
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'io.grpc:grpc-core:1.4.0'

    // Support libraries
    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support:cardview-v7:$supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$supportLibraryVersion"

    // gRPC
    compile "io.grpc:grpc-okhttp:$grpcVersion"
    compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
    compile "io.grpc:grpc-stub:$grpcVersion"
    compile 'javax.annotation:javax.annotation-api:1.2'
    protobuf 'com.google.protobuf:protobuf-java:3.3.1'

    // OAuth2 for Google API
    compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
        exclude module: 'httpclient'
    }

    // Tests
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}

build.gradle(项目:项目名称):

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        // for gRPC
        classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.0"
//        compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.8'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        maven {
            url "https://jitpack.io"
        }
    }
}

现在,当我尝试import com.google.cloud.speech.v1.SpeechGrpc;我收到错误Cannot resolve symbol 'SpeechGrpc'. But import com.google.cloud.speech.v1.RecognitionAudio or RecognizeRequest等等工作正常。

我尝试添加示例项目应用程序模块 https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech/app作为模块,它甚至不允许我使用import com.google.cloud。所以,我要么需要导入解决方案Grpc或正确的 gradle 设置以使用 google 的语音 API


如果您添加原型目录 https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech/app/src/main在 GoogleCloudPlatform/android-docs-samples 上添加到您的 android 应用程序源(app/src/main/),即使您不编写 [compile group: 'com.google.cloud', name: 'google-] ,它也会正常工作cloud-speech', version: '0.17.1-alpha'] 在你的 build.gradle(Module:app) 上。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 Android 中导入 com.google.cloud.speech.v1.SpeechGrpc 的相关文章

随机推荐

  • Azure AD B2C - 从所有会话中注销用户

    我有 3 个网站使用一个 B2C 租户 我被要求进行设置 以便当用户退出一个网站时 退出所有网站 如果他们的帐户被删除 情况也是如此 我认为我必须在每个请求上引入对 Azure 的调用 以确定用户是否仍然登录 但据我所知 没有一个 Grap
  • 如何禁用 HTML 标签?

    如果已经设置了标签 我想禁用它 例如 使用禁用菜单disabled true 或者其他的东西 我可以使用 PHP 完全删除标签 但我已经设计了它的样式 只想禁用它 是否可以 不 据我所知 没有任何仅 CSS 的方法可以按照您描述的方式禁用链
  • Python 字符串格式化:“%”比“format”函数更有效吗?

    我想比较不同的变量以在 Python 中构建字符串 using 连接 称为 加 using using join list using format功能 using 0
  • WPF:TreeViewItem 绑定到 ICommand

    我正忙于在 WPF 中创建我的第一个 MVVM 应用程序 基本上我遇到的问题是我有一个 TreeView System Windows Controls TreeView 我已将其放置在 WPF 窗口上 我决定将绑定到 CommandVie
  • 更改表类似

    是否可以在 ALTER TABLE 上使用类似于 MySQL 中的 CREATE TABLE 的 LIKE 语句 例如 创建表 db tbl1 像 db tbl2 这会克隆数据库表的结构 我想更改具有相同列的现有表 但要选择另一个表的主键
  • 如何设置字符串的颜色[重复]

    这个问题在这里已经有答案了 有谁知道我将如何设置将使用打印的字符串的颜色System out 这是我目前拥有的代码 System out println TEXT THAT NEEDS TO BE A DIFFERENT COLOR 安慰
  • 将 pandas 数据框中的多列拆分为行

    我有一个 pandas 数据框 如下所示 ticker account value date aa assets 100 200 20121231 20131231 bb liabilities 50 150 20141231 201312
  • 正则表达式的局限性? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • Typescript 创建模块

    我想为我们的库创建模块 所以每次我们调用时 我们都可以使用import Api Map from ourlibrary 目前我正在使用以下 import Api from Library Api import MapPage from ma
  • 非常非常大的实体组的交易

    我正在尝试设计一个可以容纳大量数据的数据模型 有大量数据经验的人对此有什么反馈吗 即 example only not meant to compile public class TransactionAccount private lon
  • 如何对每小时时间序列重新采样以在特定时间开始并在 24 小时后结束

    我想从一天中的特定时间开始 在我的情况下 将从 2020 年 2 月 1 日 06 UTC 开始 对我的数据框进行重新采样 包括每小时降水量值 频率为 24 小时 2020 02 01 每小时数据帧图像 I tried df df resa
  • PHP,如何重定向/转发带标头和正文的 HTTP 请求?

    我有一个 PHP 页面 main php 位于服务器 1 上 我在服务器 2 上有一个 PHP 页面 main php 同一页面 不同的代码 main php 是一个 Web 服务 我想转发对服务器 1 服务器 2 发出的完整 HTTP 请
  • Angular - 生成的表格单元格上的(单击)事件

    我一直在尝试在动态生成的表格中的单元格上添加 单击 事件 HTMLtoAdd any Input roles string ngOnInit let alphabet A B C D E F G H I J K L M N O P Q R
  • 如何用类创建div

    我正在尝试创建一个 div 并给他上一堂课 但它不起作用 有人可以帮助我吗 document ready function input type checkbox each function this after div div class
  • Vue.js - 如何将 props 传递给孙子

    我有以下应用程序结构 RegistrationView holds the data logic like get post RegistrationForm holds the form Registration Radio Compon
  • 使用 JSch 跳过 Kerberos 身份验证提示 [重复]

    这个问题在这里已经有答案了 我正在使用Connect 方法中的Ssh下面的 Java 类用于使用 SSH JSch 连接到服务器并在服务器中运行命令 问题是运行时Connect 服务器提示以下消息 Kerberos username Ker
  • clojure 中惯用的文件锁定?

    我有一组来自队列的 future 处理作业 涉及写入文件 确保一次只有一个未来访问特定文件的惯用方法是什么 使用代理而不是锁来确保这一点怎么样 我认为使用代理来保护共享的可变状态 无论它是在内存中还是在磁盘上 在 clojure 中比使用锁
  • 活动标题语言有问题

    我的应用程序中有两种语言 值 strings xml and 值 ru strings xml当我以编程方式更改语言时 所有字符串都会翻译 但活动标题不变 我在所有活动中使用 SharedPreferences prefs Preferen
  • 如何对列表使用二分查找

    让我们从 List BinarySearch 的重载开始 public int BinarySearch T item IComparer
  • 无法在 Android 中导入 com.google.cloud.speech.v1.SpeechGrpc

    我正在尝试使用谷歌的语音API https github com GoogleCloudPlatform android docs samples tree master speech Speech在Android项目中 示例项目有效 我在