RevenueCat / purchases-kmp

RevenueCat SDK for Kotlin Multiplatform
MIT License
99 stars 3 forks source link

iOS Crash when calling Purchases.configure with error configureWithAPIKey unrecognized selector sent to class #216

Open brahyam opened 1 month ago

brahyam commented 1 month ago

Describe the bug A clear and concise description of what the bug is. The more detail you can provide the faster our team will be able to triage and resolve the issue. Do not remove any of the steps from the template below. If a step is not applicable to your issue, please leave that step empty.

I'm trying to integrate the KMP SDK into a KMP app (including the Paywall UI). However when calling from KMP

val purchasesConfig = PurchasesConfiguration(apiKey) {
   appUserId = userId
}
Purchases.configure(purchasesConfig)

The iOS app crashes with the error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[RCPurchases configureWithAPIKey:appUserID:purchasesAreCompletedBy:userDefaultsSuiteName:platformFlavor:platformFlavorVersion:storeKitVersion:dangerousSettings:shouldShowInAppMessagesAutomatically:verificationMode:]: unrecognized selector sent to class 0x106566110'
  1. Environment
    1. Platform: iOS
    2. SDK version: 1.0.1+13.2.1
    3. OS version: 17.2
    4. IDE (e.g. Android Studio, Xcode, Fleet): Android Studio , Xcode
    5. IDE version: Android Studio Koala Feature Drop | 2024.1.2, Xcode Version 15.2 (15C500b)
    6. Device and/or emulator/simulator:
      • [x] Device
      • [X] Emulator/simulator
    7. Environment:
      • [X] Closed testing / Sandbox
      • [ ] TestFlight
      • [X] Production
    8. How widespread is the issue. Percentage of devices affected. 100%
  2. Debug logs that reproduce the issue No logs as the SDK is not able to initialize.
  3. Steps to reproduce, with a description of expected vs. actual behavior
    • Add Purchases.configure(purchasesConfig) to KMP
    • Run the app. Expected SDK is initialized Actual App Crashes
  4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.) I added a Pod to link the Hybrid framework as in the docs. This is my Pod.lock
    
    PODS:
    - PurchasesHybridCommon (13.2.1):
    - RevenueCat (= 5.3.3)
    - RevenueCat (5.3.3)

DEPENDENCIES:

SPEC REPOS: trunk:

SPEC CHECKSUMS: PurchasesHybridCommon: 7955b21cc5a8be78cea6dcf92f3906f3e5cec972 RevenueCat: d9e8b1b56bf81483cf8bb902a952a2da8749b964

PODFILE CHECKSUM: 40220c225a9794bced0d516b00d95455a7211622

COCOAPODS: 1.15.2


This is my lib.versions.toml

revenuecat-purchases = "1.0.1+13.2.1"

revenuecat-purchases-core = { module = "com.revenuecat.purchases:purchases-kmp-core", version.ref = "revenuecat-purchases" } revenuecat-purchases-datetime = { module = "com.revenuecat.purchases:purchases-kmp-datetime", version.ref = "revenuecat-purchases" } revenuecat-purchases-ui = { module = "com.revenuecat.purchases:purchases-kmp-ui", version.ref = "revenuecat-purchases" }


This is my gradle

kotlin { ... listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { it.binaries.framework { baseName = "shared" isStatic = true ... } }

sourceSets { commonMain.dependencies { ... implementation(libs.revenuecat.purchases.core) implementation(libs.revenuecat.purchases.datetime) implementation(libs.revenuecat.purchases.ui)

Additional context KMP app, targeting android and iOS only. using XCframeworks other possible relevant versions: agp = "8.4.1" kotlin = "2.0.0" jetbrains-compose = "1.6.10"

JayShortway commented 1 month ago

Hi, thanks for the detailed report! I'm not entirely sure what's going wrong, as everything you shared looks correct.

The "unrecognized selector" error usually points to the linked framework (pod) being different from what the Kotlin code expects.

Some thoughts/questions/leads:

brahyam commented 1 month ago

Thanks @JayShortway will try again and paste the results shortly. Is there a way of achieving this without having to use CocoaPods? I'm not using them in my project and had to include them because of this.

I'm currently using https://github.com/mirzemehdi/KMPRevenueCat which doesnt need me to use Cocoapods and trying to migrate to the official one.

Also FYI the UI library is missing from the official docs installation section and the SDK reference,

JayShortway commented 1 month ago

Is there a way of achieving this without having to use CocoaPods?

Thanks for this feedback. You're the third one to ask, so it seems we should do something about it. 😄 The PR linked above should make it possible to integrate without CocoaPods.

Also FYI the UI library is missing from the official docs installation section and the SDK reference,

Regarding the Paywall docs, they are separate: https://www.revenuecat.com/docs/tools/paywalls. Regarding the SDK reference, you are right! That should be fixed by https://github.com/RevenueCat/purchases-kmp/pull/207, meaning they'll get updated with our next release.

JayShortway commented 1 month ago

Hi @brahyam, you should now be able to integrate PurchasesHybridCommonUI without CocoaPods. Here's the URL to the repo: https://github.com/RevenueCat/purchases-hybrid-common/. Let me know how this works for you!

adrianegraphene commented 1 month ago

Oh boy, I am so looking forward to this. I only started the CocoaPods integration because of the Paywall, but that has been a lift that has stalled me for a week now. Will see if I can try with the SPM side of things, thank you.

adrianegraphene commented 1 month ago

Edit: I guess SPM hasn't picked up the new commit yet. So for now, you can use specify commit 886951d557fe8849dd1944548da1772d88968978 when selecting the package from this URL and it'll work as expected. https://github.com/RevenueCat/purchases-hybrid-common/

BELOW ISSUES RESOLVED - SEE EDIT ABOVE FYI @JayShortway I've tried a couple of different ways to add the Repo via Swift Package Manager and cannot get it to resolve. Maybe it's just me? I've tried both https://github.com/RevenueCat/purchases-hybrid-common/ image

and https://github.com/RevenueCat/purchases-hybrid-common.git image

JayShortway commented 1 month ago

@adrianegraphene Thanks for figuring this out! It's probably because the Package.swift file doesn't exist at the 13.2.1 tag. Will get a new release out so this workaround is no longer needed.

JayShortway commented 1 month ago

@adrianegraphene @brahyam Just FYI: starting with version 1.1.0+13.3.0 you should be able to integrate PurchasesHybridCommonUI using the 13.3.0 version instead of the commit.

brahyam commented 1 month ago

@JayShortway I just tried and I'm still getting the same error as @adrianegraphene (using both urls he mentioned)

Screenshot 2024-09-28 at 13 57 31

I even tried using a commit number but still fails. But I clicked on add anyway and it worked.

Could it be because I still had the regular iOS RC package added?. After adding this one the package sync was failing to I had to remove the iOS one and reset packages cache for it to work.

Would be great if you could update the docs to show this way of adding it without using pods

JayShortway commented 1 month ago

Hi @brahyam, the docs have just been updated. This section is the one explaining how to integrate PurchasesHybridCommon using Swift Package Manager.

It's indeed likely that your issue was caused by the fact that you still had the regular RevenueCat package added. PurchasesHybridCommon depends on RevenueCat. Maybe the version you added was different from the one PurchasesHybridCommon expects. In any case, the regular RevenueCat package should not be added manually.