5

I'm getting this crash only on some devices. This happens right when I try to build a new BillingClient.

And I can't properly debug this issue since it doesn't happen on any of my devices. Again, this doesn't happen in every device, Only in, like 10% of devices that installed my app.

Here's how I init billing:

class BillingManager(
    private val context: Context,
    private val firebase: FirebaseManager,
    private val storage: SharedPreferenceStorage
) {

    private var billingClient: BillingClient? = null
    val initBillingResponse = MutableLiveData<Boolean?>()

    private val startConnectionListener = object : BillingClientStateListener {
        override fun onBillingSetupFinished(result: BillingResult) {
            if (result.isResponseOk()) {
                getSKUs()
                checkSubscription()
                initBillingResponse.postValue(true)
            } else {
                initBillingResponse.postValue(false)
            }
        }

        override fun onBillingServiceDisconnected() {
            initBillingResponse.postValue(false)
        }
    }
  
    init {
        initBilling()
    }

    private fun initBilling() {
        initBillingResponse.postValue(null)

        try {
            billingClient = BillingClient.newBuilder(context)
                .enablePendingPurchases()
                .setListener { billingResult, purchases ->
                    if (billingResult.isResponseOk()) {
                        acknowledgePurchases(purchases)
                        checkSubscription()
                    } else {
                        billingResult.responseCode
                    }
                }
                .build()

            billingClient?.startConnection(startConnectionListener)
        } catch (e: Throwable) {
            e.printStackTrace()
            FirebaseCrashlytics.getInstance().recordException(e)
            initBillingResponse.postValue(false)
        }
    }

    // Other functions
}
Peyman
  • 941
  • 8
  • 28
  • +1 I have also noticed in Firebase Crashlytics some errors such as this one on my app. I am also wondering what might be the cause. Same as in your case, I could not replicate the issue during the tests, so it only happens for some devices but this results in some bad user experience. So far I haven't found any solution. Have you, @Peyman? – Alexandru Dumitru Nov 28 '21 at 08:38
  • @AlexandruDumitru I have not. Even with upgrading the billing library, it still happens. – Peyman Nov 28 '21 at 10:12
  • Same to me. Currently, I have this on 18 users and 25 crashes in total since 7 days. Because this from 2021 I hope there is now a solution to this? – chrisonline Nov 17 '22 at 08:34

0 Answers0