我正在尝试在我的应用中创建Google登录,但是当我单击Google登录按钮时,应用崩溃了。它将引发错误android.content.ActivityNotFoundException。
我尝试修复和更新Google SignIn代码和软件包。我添加了活动,说它缺少“”。 在目录〜/ flutter / .pub-cache / hosted / pub.dartlang.org / firebase_auth-//中添加了依赖项{... api'com.google.android.gms:play-services-auth:16.0.1'} android / build.gradle。另外,尝试清除缓存。
Google身份验证代码:
import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
abstract class BaseAuth {
Future<FirebaseUser> googleSignIn();
}
class Auth implements BaseAuth {
FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
@override
Future<FirebaseUser> googleSignIn() async {
final GoogleSignIn _googleSignIn = GoogleSignIn();
final GoogleSignInAccount googleAccount = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
idToken: googleAuth.idToken, accessToken: googleAuth.accessToken);
try{
FirebaseUser user = await _firebaseAuth.signInWithCredential(credential);
return user;
}catch(e){
print(e.toString());
return null;
}
} }
使用Google SignIn方法的按钮的代码:
FloatingActionButton(
heroTag: "btn2",
onPressed: () async{
FirebaseUser user = await auth.googleSignIn();
if(user == null){
changeScreenReplacement(context, NavBar());
}
},
child: Image.asset("images/Google_cirle512.png"),
),
这里的错误
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): Failed to handle method call
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.rent_app/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}; have you declared this activity in your AndroidManifest.xml?
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.app.Activity.startActivityForResult(Activity.java:4586)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.app.Activity.startActivityForResult(Activity.java:4544)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at io.flutter.plugins.googlesignin.GoogleSignInPlugin$Delegate.signIn(GoogleSignInPlugin.java:292)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at io.flutter.plugins.googlesignin.GoogleSignInPlugin.onMethodCall(GoogleSignInPlugin.java:77)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:90)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:234)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at
android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/google_sign_in( 1801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
D/AndroidRuntime( 1801): Shutting down VM
E/AndroidRuntime( 1801): FATAL EXCEPTION: main
E/AndroidRuntime( 1801): Process: com.example.rent_app, PID: 1801
E/AndroidRuntime( 1801): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=53293, result=0, data=null} to activity {com.example.rent_app/com.example.rent_app.MainActivity}: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 1801): at android.app.ActivityThread.deliverResults(ActivityThread.java:4360)
E/AndroidRuntime( 1801): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4402)
E/AndroidRuntime( 1801): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
E/AndroidRuntime( 1801): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/AndroidRuntime( 1801): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/AndroidRuntime( 1801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
E/AndroidRuntime( 1801): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 1801): at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 1801): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/AndroidRuntime( 1801): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 1801): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 1801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime( 1801): Caused by: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 1801): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:126)
E/AndroidRuntime( 1801): at
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:230)
E/AndroidRuntime( 1801): at io.flutter.plugins.googlesignin.GoogleSignInPlugin$Delegate.finishWithError(GoogleSignInPlugin.java:386)
E/AndroidRuntime( 1801): at io.flutter.plugins.googlesignin.GoogleSignInPlugin$Delegate.onActivityResult(GoogleSignInPlugin.java:524)
E/AndroidRuntime( 1801): at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:204)
E/AndroidRuntime( 1801): at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:132)
E/AndroidRuntime( 1801): at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:142)
E/AndroidRuntime( 1801): at android.app.Activity.dispatchActivityResult(Activity.java:7454)
E/AndroidRuntime( 1801): at android.app.ActivityThread.deliverResults(ActivityThread.java:4353)
E/AndroidRuntime( 1801): ... 11 more
E/flutter ( 1801): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unable to find explicit activity class {com.example.rent_app/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}; have you declared this activity in your AndroidManifest.xml?, null)
E/flutter ( 1801): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter ( 1801): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter ( 1801): <asynchronous suspension>
E/flutter ( 1801): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:344:48)
E/flutter ( 1801): <asynchronous suspension>
E/flutter ( 1801): #3 GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:218:23)
E/flutter ( 1801): <asynchronous suspension>
E/flutter ( 1801): #4 GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:257:20)
E/flutter ( 1801): #5 GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:324:48)
E/flutter ( 1801): #6 Auth.googleSignIn (package:rent_app/auth.dart:14:67)
E/flutter ( 1801): <asynchronous suspension>
E/flutter ( 1801): #7 _LoginPageState.build.<anonymous closure> (package:rent_app/login_page.dart:176:58)
E/flutter ( 1801): <asynchronous suspension>
E/flutter ( 1801): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter ( 1801): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter ( 1801): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 1801): #11 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter ( 1801): #12 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter ( 1801): #13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter ( 1801): #14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter ( 1801): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter ( 1801): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 1801): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 1801): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 1801): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 1801): #20 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 1801): #21 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 1801): #22 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 1801): #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 1801): #24 _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter ( 1801): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
E/flutter ( 1801):
I/Process ( 1801): Sending signal. PID: 1801 SIG: 9