无法在Android中导入com.google.cloud.speech.v1.SpeechGrpc [英] Cannot import com.google.cloud.speech.v1.SpeechGrpc in Android

查看:1230
本文介绍了无法在Android中导入com.google.cloud.speech.v1.SpeechGrpc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Google的Speech API

a>在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
buildToolsVersion25.0.3

defaultConfig {
applicationIdApplicationID
minSdkVersion 16
targetSdkVersion 24
// compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_5
// targetCompatibility JavaVersion.VERSION_1_5
//

signingConfigs {
release {
storeFile文件(project.properties.storeFile)
storePassword project.properties.storePassword
keyAlias project.properties.keyAlias
keyPassword project.properties .keyPassword


productFlavors {
dev {
//支持平台multi-dex的最低版本
minSdkVersion 21
}
prod {
//可以运行gRPC(TLS扩展)的最低版本
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.forcecom.android.support:support-annotations:$supportLibraryVersion
}
}

protobuf {
protoc {
artifact ='com.google.protobuf:protoc:3.3.0'
}
插件{
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 {
//选项已添加到--grpc_out
选项'lite'
}
}
}
}
}

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

依赖关系{
// compile'c​​om.android.support :support-v4:18.0.0'
//编译'com.android.support:appcompat-v7:24.2.1'
//编译'com.google.apis:google-api-services -speech:v1-rev8-1.22.0'
编译组:'com.google.cloud',名称:'google-cloud-speech',版本:'0.17.1-alpha'
//编译'com.google.android.gms:play-services:11.0.2'
编译项目(':lib')//这是另外一个库,我使用
compile'c​​om。 android.support:appcompat-v7:25.3.1'
编译'io.grpc:grpc-core:1.4.0'

//支持库
compilecom。 android.support:design:$supportLibraryVersion
compilecom.android.support:cardview-v7:$supportLibraryVersion
compilecom.android.support:recyclerview-v7:$supportLibraryVersion

// gRPC
编译io.grpc:grpc-okhttp:$ grpcVersion
编译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'
}

//测试
testCompile'junit:junit:4.12'
androidTestCompile'c​​om.android.support.test:runner:0.5'
androidTestCompile'c​​om.android .support.test.espresso:espresso-core:2.2.2'
}

构建.gradle(Project:ProjectNAME):

  //顶层构建文件,您可以在其中添加对所有子项都通用的配置选项,项目/模块。 
buildscript {
repositories {
jcenter()
maven {url'https://maven.google.com'}
}
依赖关系{
classpath'com.android.tools.build:gradle:2.3.3'
// for gRPC
classpathcom.google.protobuf:protobuf-gradle-plugin:0.8.0
// compile'c​​om.github.adrielcafe:AndroidAudioConverter:0.0.8'
}
}

allprojects {
存储库{
jcenter ()
maven {url'https://maven.google.com'}
maven {
urlhttps://jitpack.io
}
}
}

现在,当我尝试 import com。 google.cloud.speech.v1.SpeechGrpc; 出现错误无法解析符号'SpeechGrpc'。但 import com.google.cloud.speech.v1.RecognitionAudio RecognizeRequest etcetera工作正常。



我尝试添加 expample项目的应用程序模块作为模块,它甚至不允许我使用 import com.google.cloud 。因此,我需要解决方案来导入 Grpc 或更正Gradle设置以使用谷歌的语音API

/ div>

如果您添加 proto目录 ,即使你不要在你的build.gradle(Module:app)上编写[compile group:'com.google.cloud',name:'google-cloud-speech',version:'0.17.1-alpha']。


I'm trying to use Google's Speech API in Android project. The example project works. I'm having trouble to use it in my own android app.

build.gradle(Module:app) :

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(Project: ProjectNAME):

// 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"
        }
    }
}

Now, When I try to import com.google.cloud.speech.v1.SpeechGrpc; I'm getting an error Cannot resolve symbol 'SpeechGrpc'. But import com.google.cloud.speech.v1.RecognitionAudio or RecognizeRequest etcetera works fine.

I've tried adding the expample project's app module as module which didn't allow me to use even import com.google.cloud. So, I either need solution to import Grpc or correct gradle settings to use google's speech API

解决方案

If you add the proto directory on GoogleCloudPlatform/android-docs-samples to your android application source(app/src/main/), it will work fine even though you don't write [compile group: 'com.google.cloud', name: 'google-cloud-speech', version: '0.17.1-alpha'] on your build.gradle(Module:app).

这篇关于无法在Android中导入com.google.cloud.speech.v1.SpeechGrpc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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