gpt4 book ai didi

android - Kotlin : Sign In using google Fails

转载 作者:行者123 更新时间:2023-11-29 22:58:54 27 4
gpt4 key购买 nike

我在 Android 代码中执行谷歌登录过程时收到以下错误日志。使用 native 按钮而不是谷歌按钮进行登录过程。根据谷歌的文档完成所有内容。谷歌文档链接:

项目 gradle:google()

应用程序 gradle:实现 'com.google.android.gms:play-services-auth:17.0.0'

错误日志:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.myapp/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2974)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at com.test.myapp.base.MyApplication$setupActivityListener$1.onActivityCreated(Unknown Source:7)
at android.app.Application.dispatchActivityCreated(Application.java:221)
at android.app.Activity.onCreate(Activity.java:1071)
at androidx.core.app.ComponentActivity.onCreate(ComponentActivity.java:75)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:335)
at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:7258)
at android.app.Activity.performCreate(Activity.java:7249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)

代码: 创建时:

val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()

// Configure Google Sign In Initialization
googleSignInClient = GoogleSignIn.getClient(this, gso)

函数:

   private fun signIn() {
val signInIntent = googleSignInClient.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
handleSignInResult(task)

}
}

private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
try {
val account = completedTask.getResult(ApiException::class.java)
Log.e(TAG, "Google sign in success : "+account!!)

} catch (e: ApiException) {
Log.e(TAG, "Google sign in failed")
Log.w(TAG, "signInResult:failed code=" + e.statusCode)
}

}

MyApplication 类的代码:

 private fun setupActivityListener() {
registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
override fun onActivityStarted(activity: Activity) {}
override fun onActivityResumed(activity: Activity) {
activeActivity = activity
}

override fun onActivityPaused(activity: Activity) {
activeActivity = null
}

override fun onActivityStopped(activity: Activity) {}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
override fun onActivityDestroyed(activity: Activity) {}
})
}

如何解决?

最佳答案

从崩溃日志看来,您将参数 savedInstanceState 标记为非空,但它可以为空。也许你应该检查 MyApplication 类中的 setupActivityListener 方法。

关于android - Kotlin : Sign In using google Fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57139488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com