我正在尝试在Android项目中使用Google的语音测试版库(google.cloud.speech.v1p1beta1.Speech)。示例项目有效。
无法识别行“ import com.google.cloud.speech.v1p1beta1.SpeechGrpc;”
在build-gradle module-app中插入了对新库的引用:
com.google.cloud:google-cloud-speech:0.62.0-beta
com.google.api.grpc:grpc-google-cloud-speech-v1p1beta1:0.39.0
为了克服这个问题,我还需要参考或更改吗?
构建版本(模块应用):
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 "com.google.cloud.android.vuspeech"
targetSdkVersion 22
versionCode 1
versionName '1.0'
}
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'
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// 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'
}
// Google Cloud Speech beta
compile('com.google.cloud:google-cloud-speech:0.62.0-beta')
compile('com.google.api.grpc:grpc-google-cloud-speech-v1p1beta1:0.39.0')
// 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'
}