private fun getReferralId() {
Firebase.dynamicLinks
.getDynamicLink(intent)
.addOnSuccessListener(this) { pendingDynamicLinkData ->
pendingDynamicLinkData?.link?.getQueryParameter(
DEEP_LINK_QUERY_PARAM_REFERRAL_ID
)?.let { refId ->
viewModel.saveReferralId(refId)
}
}
}
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter pendingDynamicLinkData at app.package.activity.MainActivity.getReferralId$lambda-2(Unknown Source:7) at app.package.activity.MainActivity.$r8$lambda$ANLS0uCuXrQe7RFQ5b0C-RFsBKE(Unknown Source:0) at app.package.activity.MainActivity$$ExternalSyntheticLambda3.onSuccess(Unknown Source:4)
version:
implementation platform("com.google.firebase:firebase-bom:28.3.1")
implementation "com.google.firebase:firebase-dynamic-links-ktx"
What is wrong here?
UPDATE
It happens when I update version of play-services-auth libs
implementation "com.google.android.gms:play-services-auth:19.2.0"
implementation "com.google.android.gms:play-services-auth-api-phone:17.5.1"
to newest version
implementation "com.google.android.gms:play-services-auth:20.0.0"
implementation "com.google.android.gms:play-services-auth-api-phone:18.0.0"
How is that even related?
it's a bug in the library due to a play services update. To fix it, you should explicitly declare that the pendingDynamicLinkData
is nullable.
Like this:
private fun getReferralId() {
Firebase.dynamicLinks
.getDynamicLink(intent)
.addOnSuccessListener(this) { pendingDynamicLinkData: PendingDynamicLinkData? ->
pendingDynamicLinkData?.link?.getQueryParameter(
DEEP_LINK_QUERY_PARAM_REFERRAL_ID
)?.let { refId ->
viewModel.saveReferralId(refId)
}
}
}
Complement to @brwngrldev's answer.
The bug was fixed in play-services-base version ( https://developers.google.com/android/guides/releases#december_16_2021 )
If you do not wish to explicitly set the field to nullable, you can update the play-services library by adding these two lines to your app's build.gradle.
implementation 'com.google.android.gms:play-services-base:18.0.1'
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
Credits: https://github.com/firebase/firebase-android-sdk/issues/2992#issuecomment-1001847825
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.