无法在 Android 中导入 com.google.cloud.speech.v1.SpeechGrpc
Cannot import com.google.cloud.speech.v1.SpeechGrpc in Android
我正在尝试在 Android 项目中使用 Google's Speech API。示例项目有效。我无法在自己的 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'
。但是 import com.google.cloud.speech.v1.RecognitionAudio
或 RecognizeRequest
等等都可以正常工作。
我尝试添加 expample project's app module 作为模块,但我什至无法使用 import com.google.cloud
。因此,我要么需要导入 Grpc
的解决方案,要么需要更正 gradle 设置以使用 google 的语音 API
如果您将 GoogleCloudPlatform/android-docs-samples 上的 proto directory 添加到您的 android 应用程序源 (app/src/main/),即使您不写 [编译组:'com.google.cloud',名称:'google-cloud-speech',版本:'0.17.1-alpha'] 在你的 build.gradle(Module:app).
在你的 build.gradle.
中添加以下依赖项
implementation 'com.google.api.grpc:grpc-google-cloud-speech-v1:1.23.0';
我正在尝试在 Android 项目中使用 Google's Speech API。示例项目有效。我无法在自己的 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'
。但是 import com.google.cloud.speech.v1.RecognitionAudio
或 RecognizeRequest
等等都可以正常工作。
我尝试添加 expample project's app module 作为模块,但我什至无法使用 import com.google.cloud
。因此,我要么需要导入 Grpc
的解决方案,要么需要更正 gradle 设置以使用 google 的语音 API
如果您将 GoogleCloudPlatform/android-docs-samples 上的 proto directory 添加到您的 android 应用程序源 (app/src/main/),即使您不写 [编译组:'com.google.cloud',名称:'google-cloud-speech',版本:'0.17.1-alpha'] 在你的 build.gradle(Module:app).
在你的 build.gradle.
中添加以下依赖项implementation 'com.google.api.grpc:grpc-google-cloud-speech-v1:1.23.0';