GoogleCloudPlatform / android-docs-samples

Apache License 2.0
375 stars 596 forks source link

Multiple dex files define Lcom/google/protobuf/AbstractMessageLite$Builder$LimitedInputStream #92

Open AnasAlmasri opened 5 years ago

AnasAlmasri commented 5 years ago

I keep getting the same error when I try to compile google cloud text-to-speech api with the speech recognition project in this repository.

Here's my app's 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'
    }

    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.3.1'

    implementation 'com.google.cloud:google-cloud-texttospeech:0.79.0-beta'

    // OAuth2 for Google API
    implementation('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'
}

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)
skull3r7 commented 5 years ago

I get the same error with:

implementation com.google.cloud:google-cloud-texttospeech:0.80.0-beta

Any solutions?