androidgoogle-authenticationsms-retriever-api

SmsRetrieverClient Crash last update


Google docs say :

Start listening for incoming messages Next, call the SMS User Consent API's startSmsUserConsent() method to start listening for incoming messages. If you know the phone number from which the SMS message will originate, specify it (otherwise, pass null). This way, the SMS User Consent API will only trigger on messages from this number.

But the last update include the change: Strict nullability annotations (@NonNull and @Nullable) are being used where previously @RecentlyNonNull and @RecentlyNullable were used. With this change, what once caused a nullness warning will now cause an error when building Kotlin code or using Java null checking frameworks. Similar annotation changes will be incrementally rolled out in future releases of other com.google.android.gms artifacts.

And now I am getting crash when using SmsRetriever. Since I am specifying null in startSmsUserConsent()

UPDATE: I use:

implementation 'com.google.android.gms:play-services-auth:19.2.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.1'

My code:

private fun startSmsUserConsent() {
    SmsRetriever.getClient(requireContext()).also {
        it.startSmsUserConsent(null)
            .addOnSuccessListener { Timber.d("LISTENING_SUCCESS") }
            .addOnFailureListener { Timber.d("LISTENING_FAILURE") }
    }
}

If we go inside startSmsUserConsent we can see this:

@RecentlyNonNull
public abstract Task<Void> startSmsUserConsent(@Nullable String var1);

When i update libraries to 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'

And now if we go inside startSmsUserConsent, we will see this:

@NonNull
public abstract Task<Void> startSmsUserConsent(@Nullable String var1);

And now when startSmsUserConsent fires I get crash

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.***.***, PID: 5183
    java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter it
        at org.***.***.ui.fragment.account.Account.startSmsUserConsent$lambda-2$lambda-0(Unknown Source:2)
        at org.***.***.ui.fragment.account.Account.$r8$lambda$IQ631PjiyctiI5X-7HCb3IAxRs0(Unknown Source:0)
        at org.***.***.ui.fragment.account.Account$$ExternalSyntheticLambda6.onSuccess(Unknown Source:2)
        at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.0:1)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 5183 SIG: 9

My build:

minSdkVersion 19
targetSdkVersion 31
Test device api 30

UPDATE: Also if I update

implementation "com.google.android.gms:play-services-maps:18.0.0"
implementation 'com.google.firebase:firebase-bom:29.0.1'

Up to version:

implementation "com.google.android.gms:play-services-maps:18.0.1"
implementation 'com.google.firebase:firebase-bom:29.0.2'

I get the same crash.Probably the problem is somewhere in "com.google.android.gms"


Solution

  • The problem has been resolved.

    [Release Notes Google Services] : https://developers.google.com/android/guides/releases

    December 16, 2021 The latest updates to play-services-base and play-services-tasks resolve the issue that can lead to runtime NPEs (NullPointerException) when handling Task results in Kotlin code. If you're using any of the library versions listed in the December 09, 2021 release, you can avoid the runtime NPEs by explicitly depending on v18.0.1 of play-services-base and play-services-tasks. Add the following to the dependencies section of your build.gradle:

    implementation 'com.google.android.gms:play-services-base:18.0.1' implementation 'com.google.android.gms:play-services-tasks:18.0.1' In January 2022, we plan to release new versions of the other artifacts released on December 09 with new POM dependencies on the 18.0.1 versions of play-services-base and play-services-tasks.

    The latest update to Firebase includes changes to:

    Firebase Android BoM (Bill of Materials) Firebase SDK for Google Analytics This Firebase release picks up the latest versions of play-services-base and play-services-tasks (v18.0.1) to fix the issue described in the December 09, 2021 release.

    For more information, see the Firebase Android SDK Release Notes.