SmsRetrieverClient 崩溃最后更新

SmsRetrieverClient Crash last update

Google 文档说:

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.

但上次更新包含更改: 在以前使用@RecentlyNonNull 和@RecentlyNullable 的地方使用了严格的可空性注释(@NonNull 和@Nullable)。通过此更改,曾经导致 nullness 警告的问题现在将在构建 Kotlin 代码或使用 Java null 检查框架时导致错误。类似的注释更改将在其他 com.google.android.gms 工件的未来版本中逐步推出。

现在我在使用 SmsRetriever 时崩溃了。因为我在 startSmsUserConsent()

中指定了 null

更新: 我使用:

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

我的代码:

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

如果我们进入 startSmsUserConsent,我们可以看到:

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

当我将库更新到版本时:

implementation 'com.google.android.gms:play-services-auth:20.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.0'

现在如果我们进入 startSmsUserConsent,我们将看到:

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

现在当 startSmsUserConsent 触发时我崩溃了

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

我的构建:

minSdkVersion 19
targetSdkVersion 31
Test device api 30

更新: 如果我更新

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

最新版本:

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

我也一样crash.Probably问题出在“com.google.android.gms”

问题已解决

[版本说明 Google 服务]: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.