我下载了此示例语音转文本项目: https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech
该项目运行正常。但是,我想添加文本到语音功能。每当我尝试编译com.google.cloud:google-cloud-texttospeech:0.70.0-beta
时,都会出现以下错误,并且项目崩溃:
Multiple dex files define Lcom/google/protobuf/AbstractMessageLite$Builder$LimitedInputStream;
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
这是我的应用程序的build.gradle:
apply plugin: 'com.google.protobuf'
apply plugin: 'com.android.application'
ext {
supportLibraryVersion = '25.4.0'
grpcVersion = '1.4.0'
}
android {
compileSdkVersion 25
flavorDimensions "default"
defaultConfig {
applicationId "com.google.cloud.android.speech"
targetSdkVersion 25
versionCode 1
versionName '1.0'
multiDexEnabled true
}
signingConfigs {
release {
storeFile file(project.properties.storeFile)
storePassword project.properties.storePassword
keyAlias project.properties.keyAlias
keyPassword project.properties.keyPassword
}
}
productFlavors {
dev {
dimension "default"
// Minimum version with platform multi-dex support
minSdkVersion 21
}
prod {
dimension "default"
// 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"
}
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'
exclude 'META-INF/INDEX.LIST'
}
}
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 {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// UI-related libraries
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
// Support libraries
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
// gRPC
implementation "io.grpc:grpc-okhttp:$grpcVersion"
implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation 'javax.annotation:javax.annotation-api:1.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
protobuf 'com.google.protobuf:protobuf-java:3.6.1'
// OAuth2 for Google API
implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
// Tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
implementation ('com.google.cloud:google-cloud-texttospeech:0.70.0-beta'){
exclude module: 'httpclient'
}
compile 'com.android.support:multidex:1.0.3'
}
task copySecretKey(type: Copy) {
def File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
from secretKey.getParent()
include secretKey.getName()
into 'src/main/res/raw'
rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)