Migrate Adapty Kotlin Multiplatform SDK to v4.3 (beta)
Adapty Kotlin Multiplatform SDK 4.3 is a beta release. It changes four behaviors:
- On Android, Google Play shows its in-app messages, such as declined payment notices, over the screens of your app by default.
- The
dismissmethod of a flow view frees the memory of the view, so your app can’t show the flow from this view again. - On iOS, the
Adapty.makePromotedPurchasemethod only accepts the product from the promoted purchase listener. - The
Adapty.activatemethod keeps the log level that your app set before the call.
4.3 also adds three error codes. Review each change in this guide to keep your app’s behavior the same and your build passing.
If you’re still on 3.x, start with Migrate to v4.1 and then follow this guide.
Quick reference
| v4.1 | v4.3 |
|---|---|
| The SDK doesn’t request Google Play messages | Google Play shows its messages over the screens of your Android app by default |
The dismiss() method of a flow view closes the flow and keeps the view in memory | dismiss() closes the flow and frees the memory of the view; dismiss(destroy = false) keeps the view in memory, to show the flow again |
A when expression over AdaptyErrorCode without an else branch compiles | It stops compiling until it covers the three new codes |
The Adapty.makePromotedPurchase method accepts a product you build yourself | It needs the product from OnPromotedPurchaseListener |
The Adapty.activate method resets the log level set with Adapty.setLogLevel | It keeps that level, unless the configuration sets one |
Google Play messages are shown by default
Google Play can show your users messages about their subscriptions, such as a notice that a payment was declined. Google Play shows a message only when an app requests it. In 4.1, the SDK sent no such requests, so your app showed no Google Play messages.
Starting from 4.3, this is the expected behavior on Android:
- Your app starts an
Activity, the Android component that displays your app’s screens. This also happens when the app returns to the foreground. - If the
Adapty.activatecall has already completed, the SDK requests Google Play messages. - Google Play decides whether the user needs a message, so a request doesn’t always show one. A message appears over the current screen, which can be a paywall.
This default mode is called auto mode. In auto mode, messages don’t appear at cold launch: see Show messages at launch on Android. If Google Play messages can appear over any screen of your app, no changes are needed. Otherwise, set manual handling of store messages, and do one of the following:
- Keep the 4.1 behavior: Set manual handling only in the Android code of your app: pass
AdaptyStoreMessagesHandling.MANUALto thewithStoreMessagesHandlingmethod fromandroidMain, for example in anactualdeclaration. Don’t call theAdapty.showStoreMessagesmethod on Android. - Choose when the messages appear: Call
Adapty.showStoreMessagesat a moment that suits your app.
To set manual handling, pass AdaptyStoreMessagesHandling.MANUAL when you activate the SDK:
import com.adapty.kmp.Adapty
import com.adapty.kmp.models.AdaptyConfig
import com.adapty.kmp.models.AdaptyStoreMessagesHandling
val config = AdaptyConfig
.Builder("PUBLIC_SDK_KEY")
.withStoreMessagesHandling(AdaptyStoreMessagesHandling.MANUAL)
.build()
Adapty.activate(configuration = config)Manual handling applies to both platforms: on iOS 16 and later, it also holds App Store messages until your app calls Adapty.showStoreMessages. For the full API, see Control store messages.
In manual mode, the stores don’t show messages on their own. If your app never calls Adapty.showStoreMessages, users never see a declined payment notice.
dismiss() frees the memory of the flow view
In 4.1, view.dismiss() and AdaptyUI.dismissFlowView(view) kept the native view in memory, with no way to free it. Starting from 4.3, these methods free the memory of the view by default, and the view can’t be presented again. The default handlers of the CloseAction action and the flowViewDidReceiveError callback free a flow view too, but never an embedded one.
If your app follows the single-use pattern, no changes are needed. If your app presents a dismissed view again, call view.dismiss(destroy = false), and free the view with view.destroy() when your app no longer needs it:
view.dismiss(destroy = false) // hide the flow, keep its state
view.present() // show the flow on the screen the user left
view.destroy() // free the memory of the viewSee Keep a closed flow for later.
New error codes
4.3 adds three error codes: BILLING_PLAN_UNAVAILABLE (1060), OPERATION_IN_PROGRESS (3201), and RESOLVER_FAILURE (3202). A when expression over AdaptyErrorCode without an else branch stops compiling: add the new codes, or an else branch. For the full list, see Handle errors.
Pass the product from the promoted purchase listener
On iOS, the product from OnPromotedPurchaseListener carries the App Store purchase intent. Starting from 4.3, the Adapty.makePromotedPurchase method needs this purchase intent to complete the purchase. A product you build yourself, or a copy of the product, worked in 4.1 and fails in 4.3. Pass the product from the listener:
import com.adapty.kmp.OnPromotedPurchaseListener
Adapty.setOnPromotedPurchaseListener(OnPromotedPurchaseListener { product ->
scope.launch {
Adapty.makePromotedPurchase(product)
}
})See Promoted in-app purchases.
Adapty.activate keeps the log level
In 4.1, the Adapty.activate method reset the log level to AdaptyLogLevel.INFO, even if your app had called Adapty.setLogLevel before it. Starting from 4.3, Adapty.activate keeps the level set with Adapty.setLogLevel, unless the configuration sets one with the withLogLevel method. See Logging.
New in 4.3
These additions are opt-in. Your existing code keeps working without them:
- Control store messages: Choose when App Store and Google Play messages appear.
- Preload placements: The
Adapty.preloadFlowsandAdapty.preloadFlowsForDefaultAudiencemethods load flows before the user reaches them. - Keep a closed flow:
view.dismiss(destroy = false)keeps a flow to present it again, andview.destroy()releases it. - 12-month commitment plans: The
product.subscription?.pricingTermsproperty describes the plan on iOS, and access levels report thebillingPlanandcommitmentInfoproperties. - Observer mode: The
Adapty.reportTransactionmethod takes an optionalappleJwsTransactionparameter. - A/B test variation name:
AdaptyFlow.variationNamereturns the name of the A/B test variation.