in-app purchase crashes when fetching products from the Play Store in Flutter
Asked Answered
H

3

20

I am facing an issue after installing and implementing in-app purchase plugin Flutter team provided. What I did so far:

  1. added 2 products on Play Store that are visible and active.
  2. submitted build for alpha testing, since that is required for in-app purchase to work.
  3. added InAppPurchaseConnection.enablePendingPurchases(); at the app launch
  4. created a sequence of requests to the app store out of which last one fails with nasty log I can't work around
bool available = await _iap.isAvailable();
  if (!available) {
    print('=========> The store cannot be reached or accessed.');
  } else {
    Set<String> _kIds = {'farm', 'forest'};
    ProductDetailsResponse productsResponse = await _iap.queryProductDetails(_kIds);
    List<ProductDetails> products = productsResponse.productDetails;
  }      
}
  1. At the moment queryProductDetails crashes every single time with the following log:
E/AndroidRuntime( 9053): java.lang.NoSuchMethodError: No virtual method getIntroductoryPriceCycles()Ljava/lang/String; in class Lcom/android/billingclient/api/SkuDetails; or its super classes (declaration of 'com.android.billingclient.api.SkuDetails' appears in /data/app/com.my.fancy.app-6ImcBn8ELPgiO8hTXXp_3Q==/base.apk)
E/AndroidRuntime( 9053):    at io.flutter.plugins.inapppurchase.Translator.fromSkuDetail(Translator.java:27)
E/AndroidRuntime( 9053):    at io.flutter.plugins.inapppurchase.Translator.fromSkuDetailsList(Translator.java:49)
E/AndroidRuntime( 9053):    at io.flutter.plugins.inapppurchase.MethodCallHandlerImpl$1.onSkuDetailsResponse(MethodCallHandlerImpl.java:185)
E/AndroidRuntime( 9053):    at com.android.billingclient.api.zzj.run(com.android.billingclient:billing@@3.0.0:8)
E/AndroidRuntime( 9053):    at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime( 9053):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9053):    at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 9053):    at android.app.ActivityThread.main(ActivityThread.java:6746)
E/AndroidRuntime( 9053):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9053):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 9053):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I've tried running this on multiple example projects, and it fails. Tried with both Kotlin and Java project, just to see if there is something buggy with one or the other, but no luck.

EDIT (fixed the issue): Issue was result of a billingClient linked in build.gradle file that was causing this issue. Once I removed it from gradle file, everything started working as expected.

Hoagland answered 13/6, 2020 at 16:58 Comment(7)
I solved mine by removing billing client library on build.gradle and vending.Billing in android manifest and reupload a new apkHalogen
Same thing was with my project. So stressful to get blocked with the release by just one line of code in config file importing billing client. And to find out that no one is experiencing the same problem already on Flutter, so I can learn from those mistakes and fix this faster.....thanks Cajurao!Hoagland
Thanks Cajurao, I also solved mine (for test iap) by removing them. But is it ok when release on Store? Do I need to add them again?Senary
Surprisingly it is working in debug build. It is crashing only in release build, why ? So, what is the solution ? Do i need to remove both billingClient dependency in gradle file and also Billing permission in manifest file ?? If we remove these two, then how will in-app-purchases code work ??Meeker
Read the 1st comment here in this thread, it tells exactly what to do to solve this.Hoagland
@Z.Cajurao Thanks man, but I really want you to write it as answer.Laurentium
@Z.Cajurao you saved my life.. I truly appreciate. god bless youDactylography
A
5

This took a while, but none of the above seemed to work for me. I found out, as I'm also using RevenueCat that the two dependencies were clashing. As of today resolving purchases_flutter to 1.2.1 instead of 1.4.3 resolved this for me.

Auspice answered 14/12, 2020 at 10:15 Comment(0)
P
0

This took a while me too, how i solved my problem: 'in_app_purchase' package and 'flutter_inapp_purchase' conflict each other. I removed 'flutter_inapp_purchase' and fix it.

Psychic answered 18/2, 2022 at 16:33 Comment(0)
H
0

I am posting this in case it may be useful to others: ":billing:4.0.0" change to ":billing:3.0.0" on build.gradle. cause google not using 4 versions

Heroics answered 27/3, 2022 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.