Mobile Payments SDK Android: Consider switching to protobuf-javalite

We’re encountering dependency conflicts in our Flutter Android application between the Square Mobile Payments SDK (which uses full protobuf) and Firebase Firestore (which uses protobuf-javalite). This is causing duplicate class definition errors for com.google.protobuf classes.

Current Situation

  • Our app uses a recent version of Firebase and Square Mobile Payments SDK 2.1.0
  • Android Mobile Payments SDK uses protobuf-java:3.25.3 both directly and through retrofit2:converter-protobuf:2.11.0
  • Firebase and other Google libraries use protobuf-javalite:3.25.1
  • These cannot coexist in the same app due to duplicate class definitions

To be clear this would affect all Android apps attempting to use a recent version of Firebase & Square Mobile Payments SDK, not just Flutter apps.

Why protobuf-lite?

  1. Google officially recommends protobuf-javalite for Android applications:

    “For Android users, it’s recommended to use protobuf Java Lite runtime because of its smaller code size. Java Lite runtime also works better with Proguard because it doesn’t rely on Java reflection and is optimized to allow as much code stripping as possible.”

  1. Firebase, being one of the most widely used mobile SDKs, has standardized on protobuf-javalite.

Request

Could you consider switching to protobuf-javalite in a future release? This would:

  • Resolve compatibility issues with Firebase and other Android libraries
  • Reduce the SDK’s footprint in apps

Workarounds Attempted

  • Forcing protobuf-javalite usage through Gradle results in runtime crashes due to missing GeneratedMessageV3 class
  • Excluding protobuf-java from the Square SDK dependency breaks functionality
  • Downgrading Firebase is not feasible due to security and feature requirements

Thank you for considering this request. We understand this might require significant changes, but it would greatly improve the SDK’s compatibility with the broader Android ecosystem. If there is some workaround I’m not aware of, I’d love to see it!

github issue

The team has a fix! They were able to reproduce and fix on there end, basically added the following excludes to the firebase firestore dependency (and make sure you also run a gradle clean before trying to build with the new excludes):


  implementation("com.google.firebase:firebase-firestore:25.1.3") {
    exclude(group = "com.google.protobuf", module = "protobuf-java")
    exclude(group = "com.google.protobuf", module = "protobuf-javalite")
    exclude(group = "com.google.firebase", module = "protolite-well-known-types")
  }

:slight_smile:

Thanks Bryan! I’ll try this first thing tomorrow

Unfortunately, I’m not able to build with just that workaround.

After trying various other exclusions and dependency overrides in the build.gradle, I’ve been able to get to runtime but either Mobile Payments SDK or Firestore crashes, depending if I’m forcing the javalite or full protobuf version respectively.

For example, when forcing the full version:

configurations.all {
    resolutionStrategy {
        force 'com.google.protobuf:protobuf-java:3.25.3'
        exclude group: 'com.google.protobuf', module: 'protobuf-javalite'
        exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
    }
}

dependencies {
    implementation("com.google.firebase:firebase-firestore:25.1.2") {
        exclude group: "com.google.protobuf", module: "protobuf-javalite"
        exclude group: "com.google.firebase", module: "protolite-well-known-types"
    }
    implementation 'com.squareup.sdk:mobile-payments-sdk:2.0.1'
}

Firestore crashes at runtime with Caused by: java.lang.VerifyError: Verifier rejected class com.google.firestore.v1.WriteResponse

Ok so I found that the Android example app builds with the suggested workaround - however, if you add cloud_firestore pub.dev dependency to the pubspec.yaml in the example app, the Android build fails with duplicate class.

I have yet to find a way to build with cloud_firestore in the pubspec