stripe-android icon indicating copy to clipboard operation
stripe-android copied to clipboard

[BUG] Getting ANR on Android 11

Open MoustafaElsaghier opened this issue 3 years ago • 6 comments

Summary

Started to get firebase ANRs while using payments with stipe and it's not form my side. main (runnable): tid=1 systid=10243 at com.stripe.android.PaymentConfiguration.(PaymentConfiguration.kt) at com.chefaa.customers.ChefaaApplication.setupStripe(ChefaaApplication.kt:163) at com.chefaa.customers.ChefaaApplication.onCreate(ChefaaApplication.kt:94) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7294) at android.app.ActivityThread.access$1700(ActivityThread.java:299) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2184) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:264) at android.app.ActivityThread.main(ActivityThread.java:8312) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

Android version

android 11

Impacted devices

Device Brand:OPPO Model:F11 Pro Operating System Version:Android 11 ANR Date:Oct 16, 2022, 11:30:38 AM App version:V5.3.58 (11112719)

Installation method

Through a gradle dependency

Dependency Versions

implementation 'com.stripe:stripe-android:20.15.0'

SDK classes

PaymentConfiguration

MoustafaElsaghier avatar Oct 16 '22 09:10 MoustafaElsaghier

Hi @MoustafaElsaghier 👋 Can you provide a small sample application for us to reproduce the issue?

tillh-stripe avatar Oct 17 '22 15:10 tillh-stripe

Unfortunately, i don't have the specific scenario for reproduce the issue. As i mentioned earlier it's delivered to the crashlytics in firebase

On Mon, Oct 17, 2022, 5:25 PM Till Hellmund @.***> wrote:

Hi @MoustafaElsaghier https://github.com/MoustafaElsaghier 👋 Can you provide a small sample application for us to reproduce the issue?

— Reply to this email directly, view it on GitHub https://github.com/stripe/stripe-android/issues/5711#issuecomment-1281050301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELECU4PVT5JMWHKXKNNUT3WDVVYNANCNFSM6AAAAAARGI7JHE . You are receiving this because you were mentioned.Message ID: @.***>

MoustafaElsaghier avatar Oct 17 '22 16:10 MoustafaElsaghier

Can you share a code snippet of what’s happening in your Application class?

tillh-stripe avatar Oct 17 '22 16:10 tillh-stripe

call this function in onCreate of Application class private fun setupStripe() { if (BuildConfig.FLAVOR == "staging") { PaymentConfiguration.init(applicationContext, getStripeTestKey()) } else { PaymentConfiguration.init(applicationContext, getStripeLiveKey()) } }

Moustafa EL-Saghier Android Developer

+2 01113970586 <+2+01113970586> | +2 01017509660 <+2+01017509660> | @.** @.**>

Gesr EL-Suez, Cairo

[image: App Social Buttons Image] https://www.linkedin.com/in/moustafaelsaghier/

On Mon, 17 Oct 2022 at 18:55, Till Hellmund @.***> wrote:

Can you share a code snippet of what’s happening in your Application class?

— Reply to this email directly, view it on GitHub https://github.com/stripe/stripe-android/issues/5711#issuecomment-1281170055, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELECU5ODOFMALEE4ERVDMDWDWAJ5ANCNFSM6AAAAAARGI7JHE . You are receiving this because you were mentioned.Message ID: @.***>

MoustafaElsaghier avatar Oct 19 '22 14:10 MoustafaElsaghier

I took a closer look at what’s happening in our PaymentConfiguration.init(), and we’re actually causing a DiskReadViolation by accessing SharedPreferences.

If you want to prevent the ANR issues for now, you could move the initialization to a background thread. Just make sure that you’re not requiring PaymentConfiguration immediately afterwards.

class ExampleApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        
        val executor = Executors.newSingleThreadExecutor()
        executor.execute {
            PaymentConfiguration.init(this, publishableKey)
        }
    }
}

I’ll bring this up with our team and see how we can avoid the need for this workaround. Does this work for you?

tillh-stripe avatar Oct 20 '22 16:10 tillh-stripe

Thank you I'll do it for now

On Thu, Oct 20, 2022, 6:16 PM Till Hellmund @.***> wrote:

I took a closer look at what’s happening in our PaymentConfiguration.init(), and we’re actually causing a DiskReadViolation by accessing SharedPreferences.

If you want to prevent the ANR issues for now, you could move the initialization to a background thread. Just make sure that you’re not requiring PaymentConfiguration immediately afterwards.

class ExampleApplication : Application() {

override fun onCreate() {

    super.onCreate()



    val executor = Executors.newSingleThreadExecutor()

    executor.execute {

        PaymentConfiguration.init(this, publishableKey)

    }

}

}

I’ll bring this up with our team and see how we can avoid the need for this workaround. Does this work for you?

— Reply to this email directly, view it on GitHub https://github.com/stripe/stripe-android/issues/5711#issuecomment-1285823686, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELECU4S6COWCDDU2UO455TWEFV4NANCNFSM6AAAAAARGI7JHE . You are receiving this because you were mentioned.Message ID: @.***>

MoustafaElsaghier avatar Oct 20 '22 21:10 MoustafaElsaghier