There is a bug with Android SDK 33 that crashes the app only in release build when using the new getParcelableExtra or more likely getParcelableArrayListExtra since this is where I get the issue.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isInterface()' on a null object reference
There seems to be a solution for Fragment but no alternative for Activity. There is also an issue tracker but was probably deleted.
Below is the code that I am using.
/**
* Extension for getting Parcelable Intent with backward compatibility support.
* */
inline fun <reified T : Parcelable> Activity.getParcelableIntent(key: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
intent.getParcelableExtra(key, T::class.java)
else {
@Suppress("DEPRECATION")
intent.getParcelableExtra(key)
}
}
/**
* Extension for getting Parcelable ArrayList Intent with backward compatibility support.
* */
inline fun <reified T : Parcelable> Activity.getParcelableArrayListIntent(key: String): java.util.ArrayList<T>? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
intent.getParcelableArrayListExtra(key, T::class.java)
else {
@Suppress("DEPRECATION")
intent.getParcelableArrayListExtra(key)
}
}
In Activity
val relatedNews = getParcelableArrayListIntent<NewsDataDomain>(INTENT_NEWS_LIST)
Despite the debug and release having both configuration on minify and shrink settings I only encounter the issue above in release build.
buildTypes {
debug {
debuggable true
minifyEnabled true
shrinkResources true
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
firebaseCrashlytics {
// No need during development, enabling it also prevents Gradle to work offline
mappingFileUploadEnabled false
}
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled true
shrinkResources true
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
Also tried adding @Keep annotation in the domain data class but still no luck.