> For the complete documentation index, see [llms.txt](https://docs.sfbx.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sfbx.io/configuration/step-3-notice-implementation-web-app-tv/android/unified-sdk/migrate-from-old-sdk.md).

# Migrate from Old SDK

### Updating the old repository

Formerly we had:

```kotlin
maven { 
  url = uri("https://artifactory.datalf.chat/artifactory/app-consent-v2-release")
}
```

From now on, it is necessary to:

```kotlin
maven { 
  url = uri("https://artifactory.datalf.chat/artifactory/appconsent")
}
```

### Implementation change

Previously, we had:

```kotlin
dependencies { 
    implementation("com.sfbx.appconsent:appconsent-ui-v3:X.Y.Z")
}
```

From now on, you must:

```kotlin
dependencies { 
    implementation("io.sfbx.appconsent:unifiedsdk:X.Y.Z")
}
```

### Change in integration

#### Imports

Before we had:

```kotlin
import com.sfbx.appconsentv3.*
```

Now the imports are as follows:

```kotlin
import io.sfbx.appconsent.unifiedsdk.*
```

#### Initializing the SDK

This is very similar to the old SDK (like many other libraries).

Before, we had:

1. Initialization of the SDK
2. Registration of callbacks to intercept the user's response
3. Attempt to display the CMP
4. Deletion of callbacks regardless of the result

```kotlin
AppConsentSDK.initialize(
  appKey = "YOUR_APP_KEY"
) { appConsentInitialized ->
  appConsentInitialized.setOnPresentNoticeListener(object : OnPresentNoticeListener {
    override fun presentConsentError(error: Throwable?) {
      appConsentInitialized.setOnPresentNoticeListener(null)
    }

     override fun presentConsentGiven() {
       appConsentInitialized.setOnPresentNoticeListener(null)
     }
  })
  
  if(false == appConsentInitialized.tryToDisplayNoticeFromUiContext(uiContext = this@MainActivity, force = false)) {
    appConsentInitialized.setOnPresentNoticeListener(null)
  }
}
```

Now :

1. Initializing the SDK
2. Display request (the display & consent response is returned directly in the method callbacks)

```kotlin
SFBX.initialize(
  context = this@MyActivity.context,
  configuration = Configuration(appkey = "YOUR-APP-KEY"),
  onCmpReady = { appconsent ->
    appconsent.presentNotice(
      context = context,
      onCmpDisplayed = { },
      onCmpNotDisplayed = { },
      onCmpClosed = { },
    )},
  onCmpOnError = { appconsentExceptions ->
     },
)
```

### Displaying the consent screen to your users

This allows your users to view their consent and modify it if necessary.

Before, we had:

```kotlin
AppConsentSDK.getInstance()
  ?.setOnPresentNoticeListener(object : OnPresentNoticeListener {
    override fun presentConsentError(error: Throwable?) {
      AppConsentSDK.getInstance()?.setOnPresentNoticeListener(null)
    }

    override fun presentConsentGiven() {
      AppConsentSDK.getInstance()?.setOnPresentNoticeListener(null)
    }
  })

  val isCmpDisplayed =
    AppConsentSDK.getInstance()?.tryToDisplayNotice(force = true) ?: false
  if (false == isCmpDisplayed) {
    AppConsentSDK.getInstance()?.setOnPresentNoticeListener(null)
  }
```

Now :

```kotlin
try {
    SFBX.getInstance()
} catch (_: Exception) {
    null
}?.displayLayer2(context,
    onCmpDisplayed = { },
    onCmpNotDisplayed = { },
    onCmpClosed = { },
)


// Alternatively, the following approach is more idiomatic Kotlin,
// using runCatching to handle the exception in a functional style.


runCatching {
    SFBX.getInstance()
}.onSuccess { appconsent ->
    appconsent.displayLayer2(context,
        onCmpDisplayed = { },
        onCmpNotDisplayed = { },
        onCmpClosed = { },
    )
}.onFailure {
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sfbx.io/configuration/step-3-notice-implementation-web-app-tv/android/unified-sdk/migrate-from-old-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
