square / square/mobile-payments-sdk-react-native

Android: protobuf-java conflicts with Firebase (protobuf-javalite) causing DuplicateClass and VerifyError

Open
#106 3 comments 0 reactions 1 assignee View on GitHub

@cesar-sosa-hol is already working on this.

Since Jun 26, 2026.

Component: Flutter Component: React Native
Dominant language
TypeScript
Stars
16
Forks
8
Avg merge
34m
Merged PRs (30d)
1

Description

Description

When using mobile-payments-sdk-react-native alongside Firebase (Firestore/Auth/Crashlytics) on Android, the build fails with DuplicateClass errors and/or the app crashes at runtime with VerifyError.

The root cause is a dependency conflict between the two SDKs:

  • Square Mobile Payments SDK (all versions 2.3.0–2.5.0) depends on com.google.protobuf:protobuf-java (full runtime)
  • Firebase Android SDKs depend on com.google.protobuf:protobuf-javalite (lite runtime)

These two protobuf variants have incompatible class hierarchies. For example, com.google.protobuf.Timestamp extends GeneratedMessage in protobuf-java but extends GeneratedMessageLite in protobuf-javalite. Firebase's compiled bytecode contains casts like (GeneratedMessageLite) Timestamp, which fail at runtime with VerifyError when protobuf-java is on the classpath.

There is no Gradle exclusion workaround that resolves this:

  • Excluding protobuf-java fixes the dex DuplicateClass build error, but Square SDK may fail if it relies on full-protobuf APIs at runtime.
  • Excluding protobuf-javalite causes a new DuplicateClass (from protolite-well-known-types) and then VerifyError at runtime because Firebase's bytecode was compiled against GeneratedMessageLite, not GeneratedMessage.

Steps to reproduce

  1. Create a React Native project using mobile-payments-sdk-react-native
  2. Add Firebase to Android: @react-native-firebase/app, @react-native-firebase/firestore, @react-native-firebase/auth, @react-native-firebase/crashlytics
  3. Run ./gradlew assembleDebug

Expected behavior

Build succeeds and app runs without crash. Both Square SDK and Firebase coexist on Android.

Actual behavior

Build-time error (DuplicateClass):

DuplicateClass com.google.protobuf.AbstractMessageLite found in modules
  protobuf-java-3.25.3.jar (com.google.protobuf:protobuf-java:3.25.3)
  protobuf-javalite-3.25.1.jar (com.google.protobuf:protobuf-javalite:3.25.1)

Runtime error if protobuf-java is excluded (VerifyError):

java.lang.VerifyError: Verifier rejected class com.google.firebase.firestore.proto.WriteResponse
  because: com.google.protobuf.Timestamp is not instance of
  com.google.protobuf.GeneratedMessageLite (declaration of
  'com.google.firestore.v1.WriteResponse' appears in
  /data/app/.../base.apk)

Environment

  • mobile-payments-sdk-react-native: 2025.12.1 (native SDK 2.3.1–2.5.0, all affected)
  • @react-native-firebase/app: 21.x
  • React Native: 0.79.x
  • Android: minSdk 28, compileSdk 35

Workaround

Exclude the Square SDK from Android autolinking (react-native.config.js) and provide a no-op JS stub for Android via platform-specific files (.android.ts). This means Square card payments are unavailable on Android.

Request

Please consider migrating the native Android SDK's protobuf dependency from protobuf-java to protobuf-javalite. Firebase and most modern Android libraries use javalite, and it is Google's recommended protobuf variant for Android. This would allow Square SDK and Firebase to coexist without conflicts.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.