我正在使用Flutter制作“使用Google登录”按钮,但是当我确定Firebase与该应用程序正确集成且SHA1正确且该应用程序正常运行时,单击该应用程序会崩溃并退出Firestore很好
这是代码和错误。
错误:
I/art (13904): Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.signin.internal.SignInHubActivity>
I/art (13904): Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.signin.internal.SignInHubActivity>
E/flutter (13904): [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(40)] java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/signin/internal/SignInHubActivity;
E/flutter (13904): at com.google.android.gms.auth.api.signin.internal.zzh.zzc(Unknown Source)
E/flutter (13904): at com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent(Unknown Source)
E/flutter (13904): at io.flutter.plugins.googlesignin.GoogleSignInPlugin$Delegate.signIn(GoogleSignInPlugin.java:291)
E/flutter (13904): at io.flutter.plugins.googlesignin.GoogleSignInPlugin.onMethodCall(GoogleSignInPlugin.java:77)
E/flutter (13904): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/flutter (13904): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/flutter (13904): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/flutter (13904): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (13904): at android.os.MessageQueue.next(MessageQueue.java:331)
E/flutter (13904): at android.os.Looper.loop(Looper.java:218)
E/flutter (13904): at android.app.ActivityThread.main(ActivityThread.java:5526)
E/flutter (13904): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (13904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/flutter (13904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/flutter (13904): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.signin.internal.SignInHubActivity" on path: DexPathList[[zip file "/data/app/com.example.tester-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.tester-1/lib/arm, /data/app/com.example.tester-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
E/flutter (13904): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/flutter (13904): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/flutter (13904): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/flutter (13904): ... 14 more
E/flutter (13904): Suppressed: java.lang.NoClassDefFoundError: com.google.android.gms.auth.api.signin.internal.SignInHubActivity
E/flutter (13904): at dalvik.system.DexFile.defineClassNative(Native Method)
E/flutter (13904): at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/flutter (13904): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/flutter (13904): at dalvik.system.DexPathList.findClass(DexPathList.java:338)
E/flutter (13904): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/flutter (13904): ... 16 more
E/flutter (13904): Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.auth.api.signin.internal.SignInHubActivity
E/flutter (13904): at java.lang.Class.classForName(Native Method)
E/flutter (13904): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/flutter (13904): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/flutter (13904): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/flutter (13904): ... 15 more
E/flutter (13904): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
E/flutter (13904):
F/flutter (13904): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(77)] Check failed: CheckException(env).
F/libc (13904): Fatal signal 6 (SIGABRT), code -6 in tid 13904 (.example.tester)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
UUID: 82d8c901-de47-4729-a4c6-a013707000ca
Build fingerprint: 'Sony/D6503/D6503:6.0.1/23.5.A.1.291/2769308465:user/release-keys'
Revision: '0'
ABI: 'arm'
pid: 13904, tid: 13904, name: .example.tester >>> com.example.tester <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: '[FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(77)] Check failed: CheckException(env).
'
r0 00000000 r1 00003650 r2 00000006 r3 b6fe9b7c
r4 b6fe9b84 r5 b6fe9b34 r6 0000000b r7 0000010c
r8 bee23e9c r9 00000000 sl 00000001 fp b6f7cc11
ip 00000006 sp bee23d78 lr b6d4ecb1 pc b6d510a0 cpsr 400f0010
backtrace:
#00 pc 000420a0 /system/lib/libc.so (tgkill+12)
#01 pc 0003fcad /system/lib/libc.so (pthread_kill+32)
#02 pc 0001c463 /system/lib/libc.so (raise+10)
#03 pc 00019615 /system/lib/libc.so (__libc_android_abort+34)
#04 pc 00017568 /system/lib/libc.so (abort+4)
#05 pc 00b0cc63 /data/app/com.example.tester-1/lib/arm/libflutter.so (offset 0xafe000)
#06 pc 00b03411 /data/app/com.example.tester-1/lib/arm/libflutter.so (offset 0xafe000)
#07 pc 00b02107 /data/app/com.example.tester-1/lib/arm/libflutter.so (offset 0xafe000)
#08 pc 00b338ef /data/app/com.example.tester-1/lib/arm/libflutter.so (offset 0xafe000)
#09 pc 00b0d3c5 /data/app/com.example.tester-1/lib/arm/libflutter.so (offset 0xafe000)
#10 pc 00b107ab /data/app/com.example.tester-1/lib/arm/libflutter.so (offset 0xafe000)
#11 pc 00012e03 /system/lib/libutils.so (_ZN7android6Looper9pollInnerEi+530)
#12 pc 00012ed3 /system/lib/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+130)
#13 pc 00082a59 /system/lib/libandroid_runtime.so (_ZN7android18NativeMessageQueue8pollOnceEP7_JNIEnvP8_jobjecti+22)
#14 pc 72d4655d /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x1f66000)
Tombstone written to: /data/tombstones/tombstone_08
代码都在main.dart中:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:provider/provider.dart';
import 'package:tester/locator.dart';
import 'package:tester/ui/views/HomeView.dart';
import 'core/viewmodels/crudModel.dart';
main(List<String> args) {
setupLocator();
runApp(TestApp());
}
class TestApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.green),
);
return MultiProvider(
providers: [
ChangeNotifierProvider(
builder: (_) => locator<CRUDModel>(),
)
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
accentColor: Colors.green,
primaryColor: Colors.green,
),
home: GoogleLoginView(),
),
);
}
}
class GoogleLoginView extends StatelessWidget {
final GoogleSignIn _googleSignInObject = GoogleSignIn();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Google Login'),
),
body: Center(
child: RaisedButton(
color: Colors.green,
splashColor: Colors.greenAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
onPressed: _googleSignIn,
child: Text('Google Sign In'),
),
),
);
}
Future<void> _googleSignIn() async {
GoogleSignInAccount _googleSignInAccount =
await _googleSignInObject.signIn().catchError((e) => print(e));
GoogleSignInAuthentication _googleSignInAuthentication =
await _googleSignInAccount.authentication.catchError((e) => print(e));
await FirebaseAuth.instance.signInWithCredential(
GoogleAuthProvider.getCredential(
idToken: _googleSignInAuthentication.idToken,
accessToken: _googleSignInAuthentication.accessToken,
),
).catchError((e) => print(e));
}
}
pubspec.yaml:
name: tester
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
provider: ^3.0.0+1
get_it: ^1.0.3+2
cloud_firestore: ^0.12.9
firebase_core: ^0.4.0+8
google_sign_in: ^4.0.6
firebase_auth: ^0.14.0+1
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- res/images/bag.jpg
- res/images/computer.jpg
- res/images/dress.jpg
- res/images/phone.jpg
- res/images/shoes.jpg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
答案 0 :(得分:2)
我遇到了同样的问题。升级到AndroidX解决了我的问题。
要将您的flutter项目升级到androidx,Android Studio可以节省时间。
步骤:
要将项目升级到androidx,请在Android Studio的flutter项目中打开 android 文件夹。
从 重构 菜单中选择 迁移到AndroidX
并应用迁移更改
flutter clean build
答案 1 :(得分:0)
我正在使用
firebase_auth:^ 0.14.0 + 2
google_sign_in:^ 4.0.6
应用级优惠券:
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
}
收到此错误。...
E / AndroidRuntime(5431):原因:java.lang.NullPointerException:尝试调用虚拟方法'android.view.View androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(android.view.View,java.lang。空对象引用上的字符串,android.content.Context,android.util.AttributeSet)
完成: 扑扑干净 清理缓存 扑扑升级 扑吧获得
答案 2 :(得分:0)
应用级build.gradle
defaultConfig {
minSdkVersion 23
}
在项目级别gradle.properties
中添加
android.useAndroidX=true
android.enableJetifier=true
在build.gradle
中添加
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
}
如果您不使用Kotlin支持,则可以跳过该Kotlin插件
不要忘记先运行flutter clean
然后运行flutter pub upgrade
这些更改帮助我防止了应用程序崩溃,它也应该为您提供帮助。