Flutter集成RevenueCat后出现IncompatibleClassChangeError导致崩溃求助
Android平台集成RevenueCat SDK后触发购买/打开付费墙时出现java.lang.IncompatibleClassChangeError崩溃
配置RevenueCat SDK后,Android平台尝试购买产品或打开付费墙时,应用抛出java.lang.IncompatibleClassChangeError错误并崩溃。目前仅针对Play Store配置了Google API Key,通过Firebase登录后以邮箱作为RevenueCat用户ID初始化SDK,相关代码及依赖配置如下:
初始化代码
Future<void> initPlatformState() async { // Enable debug logs before calling `configure`. await Purchases.setLogLevel(LogLevel.debug); /* - appUserID is nil, so an anonymous ID will be generated automatically by the Purchases SDK. Read more about Identifying Users here: https://docs.revenuecat.com/docs/user-ids - observerMode is false, so Purchases will automatically handle finishing transactions. Read more about Observer Mode here: https://docs.revenuecat.com/docs/observer-mode */ PurchasesConfiguration configuration; configuration = PurchasesConfiguration(googleApiKey) ..appUserID = null ..observerMode = false; await Purchases.configure(configuration); await Purchases.enableAdServicesAttributionTokenCollection(); appData.appUserID = await Purchases.appUserID; Purchases.addCustomerInfoUpdateListener((customerInfo) async { appData.appUserID = await Purchases.appUserID; CustomerInfo customerInfo = await Purchases.getCustomerInfo(); (customerInfo.entitlements.all[entitlementID] != null && customerInfo.entitlements.all[entitlementID]!.isActive) ? appData.entitlementIsActive = true : appData.entitlementIsActive = false; //setState(() {}); }); } @override void initState() { initPlatformState(); super.initState(); }
产品购买触发代码
InkWell( onTap: () async { if (_isMathA == true) { Navigator.push( context, MaterialPageRoute( builder: (context) => const CourseMathAScreen()), ); } else { try { Offerings offerings = await Purchases.getOfferings(); var package = offerings.getOffering("Math A Course")?.lifetime; await Purchases.purchasePackage(package!); setState(() { _isMathA = true; }); } catch (e) { debugPrint("Failed to purchase product: $e"); } } }, child: CourseWidget( path: "assets/images/math.png", title: "Mathematics A", subtitle: "MEXT Mathematics course A (beginner) broken down into chapters:\nNumbers and expressions\nQuadratic functions\nFigures and measurements\nThe number of possible outcomes and probability\nProperties of integers\nProperties of figures", price: _isMathA ? "OPEN" : "\$17", ), ),
付费墙检查代码
void checkUserPaywall(context, doFunction) async { CustomerInfo customerInfo = await Purchases.getCustomerInfo(); if (customerInfo.entitlements.all[entitlementID] != null && customerInfo.entitlements.all[entitlementID]!.isActive == true) { doFunction(); } else { Offerings offerings; try { offerings = await Purchases.getOfferings(); if (offerings == null || offerings.current == null) { //offerings are empty show message to user } else { //show paywall await showModalBottomSheet( useRootNavigator: true, isDismissible: true, isScrollControlled: true, backgroundColor: Styles.orangeColor, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(25))), context: context, builder: (BuildContext context) { return StatefulBuilder( builder: (BuildContext context, StateSetter setModalState) { return Paywall( offering: offerings.current, ); }); }); } } on PlatformException catch (e) { await showDialog( context: context, builder: (context) { return SimpleDialog( title: const Text("Error"), children: [Text('${e.message}')], ); }); } } }
app build.gradle依赖配置
dependencies { def billing_version = "5.1.0" implementation platform('com.google.firebase:firebase-bom:31.3.0') implementation "com.revenuecat.purchases:purchases:6.0.0" implementation "com.android.billingclient:billing:$billing_version" implementation "com.android.billingclient:billing-ktx:$billing_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
已尝试执行pub clean、pub cache repair、移除billing client依赖等操作,打包appbundle安装到手机后仍崩溃,请求技术支持。
内容的提问来源于stack exchange,提问作者Andrei Rosca
相关产品推荐
相关产品推荐

