Repository: flutter
Issue: [in_app_purchase] in android causing crashes in some devices
Labels: c: crash,platform-android,p: in_app_purchase,package,perf: memory,P2,team-android,triaged-android

### Steps to reproduce

`   await _inAppPurchase.queryProductDetails(productIds);`
calling query product details causing error 


### Expected results

it shouldn't cause any crashes

### Actual results

it causing app to crash

### Code sample

<details open><summary>Code sample</summary>

```dart
[Paste your code here]
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

![image](https://github.com/user-attachments/assets/98ade6d8-ed7e-4fdf-8f99-c5acdb598aed)
![image](https://github.com/user-attachments/assets/11fc3e0c-df2d-4417-aa16-d4a95a1a66fe)
![image](https://github.com/user-attachments/assets/e61c8949-e4d0-4ebb-8483-0258aaebfbc5)
![image](https://github.com/user-attachments/assets/6c87b3cc-bd5d-4052-9d5f-f662d5d7543b)


</details>


### Logs

<details open><summary>Logs</summary>


```
Exception java.lang.OutOfMemoryError:
    at com.google.android.gms.internal.play_billing.zzgr.zzy (zzgr.java)
    at com.google.android.gms.internal.play_billing.zzdd.zzj (zzdd.java)
    at com.google.android.gms.internal.play_billing.zzcz.<init> (zzcz.java)
    at com.google.android.gms.internal.play_billing.zzgn.<init> (zzgn.java)
    at com.google.android.gms.internal.play_billing.zzgr.zzy (zzgr.java)
    at com.google.android.gms.internal.play_billing.zzdd.zzh (zzdd.java)
    at com.google.android.gms.internal.play_billing.zzgr.zzz (zzgr.java)
    at com.android.billingclient.api.zzbx.zzb (zzbx.java)
    at com.android.billingclient.api.BillingClientImpl.queryProductDetailsAsync (BillingClientImpl.java)
    at io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.queryProductDetailsAsync (MethodCallHandlerImpl.java)
    at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage (BasicMessageChannel.java)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler (DartMessenger.java)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0 (DartMessenger.java)
    at android.os.Handler.handleCallback (Handler.java:942)
    at android.os.Handler.dispatchMessage (Handler.java:99)
    at android.os.Looper.loopOnce (Looper.java:201)
    at android.os.Looper.loop (Looper.java:288)
    at android.app.ActivityThread.main (ActivityThread.java:8010)
    at java.lang.reflect.Method.invoke
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:566)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)
```

### io.flutter.plugin.common.StandardMessageCodec.writeValue
```

Exception java.lang.OutOfMemoryError:
    at java.lang.StringFactory.newStringFromBytes
    at java.lang.StringLatin1.newString (StringLatin1.java:738)
    at java.lang.StringBuilder.toString (StringBuilder.java:474)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0 (DartMessenger.java)
    at android.os.Handler.handleCallback (Handler.java:942)
    at android.os.Handler.dispatchMessage (Handler.java:99)
    at android.os.Looper.loopOnce (Looper.java:201)
    at android.os.Looper.loop (Looper.java:288)
    at android.app.ActivityThread.main (ActivityThread.java:8010)
    at java.lang.reflect.Method.invoke
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:566)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)
```
### io.flutter.plugin.common.StandardMessageCodec.writeValue

```
Exception java.lang.OutOfMemoryError:
    at libcore.util.CharsetUtils.toUtf8Bytes
    at java.lang.String.getBytes (String.java:1207)
    at io.flutter.plugin.common.StandardMessageCodec.writeValue (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.writeValue (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.writeValue (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.writeValue (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.writeValue (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.writeValue (Messages.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.writeValue (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.writeValue (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.writeValue (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.encodeMessage (StandardMessageCodec.java)
    at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler$1.reply (BasicMessageChannel.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApi$7.success (Messages.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApi$7.success (Messages.java)
    at io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.lambda$queryProductDetailsAsync$4 (MethodCallHandlerImpl.java)
    at com.android.billingclient.api.BillingClientImpl.queryProductDetailsAsync (BillingClientImpl.java)
    at io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.queryProductDetailsAsync (MethodCallHandlerImpl.java)
    at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage (BasicMessageChannel.java)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler (DartMessenger.java)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0 (DartMessenger.java)
    at android.os.Handler.handleCallback (Handler.java:942)
    at android.os.Handler.dispatchMessage (Handler.java:99)
    at android.os.Looper.loopOnce (Looper.java:201)
    at android.os.Looper.loop (Looper.java:288)
    at android.app.ActivityThread.main (ActivityThread.java:8010)
    at java.lang.reflect.Method.invoke
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:566)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)
```
```
Exception java.lang.OutOfMemoryError:
    at io.flutter.plugin.common.StandardMessageCodec.readValueOfType (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.readValueOfType (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.readValue (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.readValueOfType (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.readValue (StandardMessageCodec.java)
    at io.flutter.plugin.common.StandardMessageCodec.readValueOfType (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.readValueOfType (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.readValue (StandardMessageCodec.java)
    at io.flutter.plugin.common.StandardMessageCodec.readValueOfType (StandardMessageCodec.java)
    at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApiCodec.readValueOfType (Messages.java)
    at io.flutter.plugin.common.StandardMessageCodec.readValue (StandardMessageCodec.java)
    at io.flutter.plugin.common.StandardMessageCodec.decodeMessage (StandardMessageCodec.java)
    at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage (BasicMessageChannel.java)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler (DartMessenger.java)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0 (DartMessenger.java)
    at android.os.Handler.handleCallback (Handler.java:942)
    at android.os.Handler.dispatchMessage (Handler.java:99)
    at android.os.Looper.loopOnce (Looper.java:201)
    at android.os.Looper.loop (Looper.java:288)
    at android.app.ActivityThread.main (ActivityThread.java:8010)
    at java.lang.reflect.Method.invoke
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:566)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)
```

```
Exception java.lang.OutOfMemoryError:
  at java.io.ByteArrayOutputStream.<init> (ByteArrayOutputStream.java:79)
  at java.io.ByteArrayOutputStream.<init> (ByteArrayOutputStream.java:64)
  at io.flutter.plugin.common.StandardMessageCodec$ExposedByteArrayOutputStream.<init> (StandardMessageCodec.java)
  at io.flutter.plugin.common.StandardMessageCodec.encodeMessage (StandardMessageCodec.java)
  at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler$1.reply (BasicMessageChannel.java)
  at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApi$7.success (Messages.java)
  at io.flutter.plugins.inapppurchase.Messages$InAppPurchaseApi$7.success (Messages.java)
  at io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.lambda$queryProductDetailsAsync$4 (MethodCallHandlerImpl.java)
  at com.android.billingclient.api.BillingClientImpl.queryProductDetailsAsync (BillingClientImpl.java)
  at io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.queryProductDetailsAsync (MethodCallHandlerImpl.java)
  at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage (BasicMessageChannel.java)
  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler (DartMessenger.java)
  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0 (DartMessenger.java)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:201)
  at android.os.Looper.loop (Looper.java:288)
  at android.app.ActivityThread.main (ActivityThread.java:8010)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:566)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0.1 24A348 darwin-arm64, locale en-PK)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.94.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!
```

</details>