How do I fix protobuf build error

100 views
Skip to first unread message

miyuki onuma

unread,
Sep 7, 2020, 7:41:35 AM9/7/20
to Protocol Buffers
Hi All!

My app now depends on protobuf-lite and protobuf-javalite, which triggers the multiple class error.

Articles that would be helpful:
  • The gradle error

```
> Task :app:minifyProductionReleaseWithR8 FAILED
/Users/miyuki.onuma/.gradle/caches/transforms-2/files-2.1/0268d94a7c4b3a93962493a637c82377/jetified-protobuf-javalite-3.11.0.jar: R8: Type com.google.protobuf.DurationOrBuilder is defined multiple times: /Users/miyuki.onuma/.gradle/caches/transforms-2/files-2.1/0268d94a7c4b3a93962493a637c82377/jetified-protobuf-javalite-3.11.0.jar:com/google/protobuf/DurationOrBuilder.class, /Users/miyuki.onuma/vmedia-recorder-android/pb/build/intermediates/runtime_library_classes_jar/release/classes.jar:com/google/protobuf/DurationOrBuilder.class
```

  • My apps build.gradle.
```
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'

android {
    compileSdkVersion rootProject.ext.compilerSdk
    defaultConfig {
        applicationId "com.sample"
        minSdkVersion rootProject.ext.minSdk
        targetSdkVersion rootProject.ext.targetSdk
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    configurations {
        implementation.exclude group: 'com.google.protobuf, module: protobuf-lite'
        implementation.exclude group: 'io.grpc, module: grpc-all'
        implementation.exclude group: 'com.google.protobuf, module: protobuf-java'
        implementation.exclude module: 'protolite-well-known-types'
        implementation.exclude module: 'com.google.protobuf'
    }

    dataBinding {
        enabled = true
    }

    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            versionNameSuffix ".debug"
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    flavorDimensions "default"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    testImplementation "org.mockito:mockito-core:2.23.0"
    androidTestImplementation "org.mockito:mockito-android:2.21.0"
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.1'

    implementation "androidx.core:core-ktx:${rootProject.ktx}"
    implementation "androidx.annotation:annotation:$rootProject.annotation"

    // For view
    implementation "androidx.appcompat:appcompat:$rootProject.appCompat"
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintlayout"
    implementation "androidx.cardview:cardview:$rootProject.cardView"
    implementation "com.google.android.material:material:$rootProject.material"
    implementation("androidx.recyclerview:recyclerview:$rootProject.recyclerView") { force = true }
    implementation "de.hdodenhof:circleimageview:$rootProject.circleimageview"

    // For network & sync
    implementation "com.google.code.gson:gson:$rootProject.ext.gson_version"
    implementation "com.squareup.okhttp3:okhttp:$rootProject.ext.okhttp_version"
    implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.ext.okhttp_version"
    implementation "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofit2_version"
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofit2_version"
    implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:$rootProject.coroutines_adapter_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$rootProject.ext.coroutines_version"

    // For load image
    implementation "com.github.bumptech.glide:glide:$rootProject.ext.glide_version"
    kapt "com.github.bumptech.glide:compiler:$rootProject.ext.glide_version"

    // For request Permission
    implementation "com.github.hotchemi:permissionsdispatcher:$rootProject.ext.dispatcher_version"
    kapt "com.github.hotchemi:permissionsdispatcher-processor:$rootProject.ext.dispatcher_version"

    // Koin for Android
    implementation "org.koin:koin-android:$rootProject.ext.koin_version"
    implementation "org.koin:koin-androidx-scope:$rootProject.ext.koin_version"
    implementation "org.koin:koin-androidx-viewmodel:$rootProject.ext.koin_version"
    androidTestImplementation("org.koin:koin-test:$rootProject.ext.koin_version") {
        exclude group: 'org.mockito'
    }

    // LeakCanary
    debugImplementation "com.squareup.leakcanary:leakcanary-android:$rootProject.ext.leakCanary"
    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$rootProject.ext.leakCanary"

    // JetPack
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycle_version"
    implementation "androidx.room:room-runtime:$rootProject.room_version"
    kapt "androidx.room:room-compiler:$rootProject.room_version"
    implementation "androidx.room:room-ktx:$rootProject.room_version"

    implementation "net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:$rootProject.keyboardEvent"

    //Protobuf and gRPC
    implementation "io.grpc:grpc-okhttp:$rootProject.grpcVersion"
    implementation ("io.grpc:grpc-protobuf-lite:${rootProject.grpcVersion}"){
        exclude module: "protobuf-lite"
        exclude module: 'protolite-well-known-types'
    }
    implementation "io.grpc:grpc-stub:$rootProject.grpcVersion"
    implementation "javax.annotation:javax.annotation-api:$rootProject.annotationJavax"

    // Firebase
    implementation "com.google.firebase:firebase-messaging:$rootProject.firebase_message"
    implementation "com.google.firebase:firebase-auth:$rootProject.firebase_auth"
    implementation "com.google.firebase:firebase-analytics:$rootProject.firebase_analytics"
    implementation "com.google.firebase:firebase-config-ktx:$rootProject.firebase_config"
    implementation("com.crashlytics.sdk.android:crashlytics:$rootProject.crashlytics") {
        transitive = true
    }
    implementation "com.google.android.gms:play-services-auth:$rootProject.play_service_auth"
    implementation "com.google.firebase:firebase-inappmessaging-display:$rootProject.inappmessaging"
    implementation "com.google.firebase:firebase-core:$rootProject.core"


    //Social
    implementation "com.facebook.android:facebook-login:$rootProject.facebook_sdk"
    implementation "com.twitter.sdk.android:twitter-core:$rootProject.ext.twitter"
    implementation "com.twitter.sdk.android:tweet-composer:$rootProject.ext.twitter"

    //Joda time
    implementation "net.danlew:android.joda:$rootProject.ext.joda"

    // OSS Licenses
    implementation "com.google.android.gms:play-services-oss-licenses:${rootProject.ossLicenses}"

    implementation "me.saket:better-link-movement-method:$rootProject.ext.link_movement"

    implementation "com.github.axet:android-audio-library:$rootProject.ext.audio_library"

    // Debug
    implementation 'com.jakewharton.timber:timber:4.7.1'
    debugImplementation 'com.willowtreeapps.hyperion:hyperion-core:0.9.27'
    debugImplementation 'com.willowtreeapps.hyperion:hyperion-crash:0.9.27'
    debugImplementation 'com.willowtreeapps.hyperion:hyperion-disk:0.9.27'
    debugImplementation 'com.willowtreeapps.hyperion:hyperion-measurement:0.9.27'
    debugImplementation 'com.willowtreeapps.hyperion:hyperion-shared-preferences:0.9.27'
    debugImplementation 'com.willowtreeapps.hyperion:hyperion-timber:0.9.27'
    debugImplementation 'com.github.Commit451:Hyperion-Chuck:1.0.0'

    implementation project(path: ':core')
    implementation project(path: ':pb')
}
apply plugin: 'com.google.gms.google-services'
```
全員に返信
投稿者に返信
転送

Reply all
Reply to author
Forward
0 new messages