First make sure you are using the latest version of UMP SDK inside your dependencies and don't rely on the version embedded with play-services-ads
, that version could be outdated.
dependencies {
implementation("com.google.android.gms:play-services-ads:22.6.0")
implementation("com.google.android.ump:user-messaging-platform:2.2.0")
}
Second, in my case Android DataStore was causing preferences reset. The same preferences file is used to store consent from UMP SDK, coincidently they had the same name. It seems that DataStore tries to migrate all preferences when it finds the preferences file, and then deletes it, which causes UMP SDK to lose stored consent info.
companion object {
private const val PREFS_FILE_NAME = "user_prefs"
private val Context.dataStore by preferencesDataStore(
name = PREFS_FILE_NAME,
produceMigrations = {
listOf(SharedPreferencesMigration(it, it.packageName + "_preferences"))
})
}
UMP SDK uses my.package.name_preferences.xml
file by default (can't change it) to store consent info. My old preferences also were stored in the same file, and when I switched to DataStore I had to make a migration from that file.
To resolve the issue, I simply removed the migration since it is not that important for me.