user924
user924

Reputation: 12145

parameter pendingDynamicLinkData specified as non-null is null

private fun getReferralId() {
    Firebase.dynamicLinks
        .getDynamicLink(intent)
        .addOnSuccessListener(this) { pendingDynamicLinkData ->
            pendingDynamicLinkData?.link?.getQueryParameter(
                DEEP_LINK_QUERY_PARAM_REFERRAL_ID
            )?.let { refId ->
                viewModel.saveReferralId(refId)
            }
        }
}

enter image description here

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?

Upvotes: 6

Views: 497

Answers (2)

Pedro Bilro
Pedro Bilro

Reputation: 1

Complement to @brwngrldev's answer.

Update

The problem was fixed in a recent version of play services library (https://developers.google.com/android/guides/releases#january_05_2022)

Check what dependencies you have in your project, and update them to the version listed in "Artifacts released on maven.google.com".

For example, in the case of the question's issue, the following dependencies need to be updated:

implementation "com.google.android.gms:play-services-auth:20.0.1"
implementation "com.google.android.gms:play-services-auth-api-phone:18.0.1"

OLD 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

Upvotes: 0

brwngrldev
brwngrldev

Reputation: 3704

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)
            }
        }
 }

Upvotes: 7

Related Questions