我有一个Flutter / Firebase应用程序,它可以在Android模拟器上运行,但不能在真实设备上运行(带有Android 8.0的HTC 10)。在Firebase身份验证代码中,它会失败并显示NullPointerException,但堆栈跟踪中不包含调用源于我的应用程序代码中的位置。
Launching lib/main.dart on HTC6545LVW in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
I/FlutterActivityDelegate(18602): onResume setting current activity to this
W/zygote64(18602): Skipping duplicate class check due to unrecognized classloader
W/DynamiteModule(18602): Local module descriptor class for com.google.firebase.auth not found.
W/BiChannelGoogleApi(18602): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@d8cd9dc
W/DynamiteModule(18602): Local module descriptor class for com.google.firebase.auth not found.
I/FirebaseAuth(18602): [FirebaseAuth:] Loading module via FirebaseOptions.
I/FirebaseAuth(18602): [FirebaseAuth:] Preparing to create service connection to gms implementation
D/SQLiteConnection(18602): DB info: open connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, flag: 0x6, FH handler: 0x73494ae600, count: 1
D/SQLiteConnection(18602): DB info: close connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, FH handler: 0x73494ae600, count: 0
Syncing files to device HTC6545LVW...
D/SQLiteConnection(18602): DB info: open connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, flag: 0x6, FH handler: 0x73494ae600, count: 1
D/SQLiteConnection(18602): DB info: close connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, FH handler: 0x73494ae600, count: 0
E/StorageHelpers(18602): Failed to turn object into JSON
E/StorageHelpers(18602): java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference
E/StorageHelpers(18602): at com.google.firebase.auth.internal.zzz.zzi(Unknown Source:126)
E/StorageHelpers(18602): at com.google.firebase.auth.internal.zzz.zzg(Unknown Source:3)
E/StorageHelpers(18602): at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source:28)
E/StorageHelpers(18602): at com.google.firebase.auth.FirebaseAuth$zza.zza(Unknown Source:12)
E/StorageHelpers(18602): at com.google.firebase.auth.api.internal.zzbn.zzaa(Unknown Source:15)
E/StorageHelpers(18602): at com.google.firebase.auth.api.internal.zzcy.zzal(Unknown Source:0)
E/StorageHelpers(18602): at com.google.firebase.auth.api.internal.zzcy.zza(Unknown Source:0)
E/StorageHelpers(18602): at com.google.firebase.auth.api.internal.zzdb.zza(Unknown Source:47)
E/StorageHelpers(18602): at com.google.firebase.auth.api.internal.zzci.dispatchTransaction(Unknown Source:34)
E/StorageHelpers(18602): at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source:22)
E/StorageHelpers(18602): at android.os.Binder.execTransact(Binder.java:682)
W/Binder (18602): Caught a RuntimeException from the binder stub implementation.
W/Binder (18602): com.google.android.gms.internal.firebase_auth.zzv: java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference
W/Binder (18602): at com.google.firebase.auth.internal.zzz.zzi(Unknown Source:151)
W/Binder (18602): at com.google.firebase.auth.internal.zzz.zzg(Unknown Source:3)
W/Binder (18602): at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source:28)
W/Binder (18602): at com.google.firebase.auth.FirebaseAuth$zza.zza(Unknown Source:12)
W/Binder (18602): at com.google.firebase.auth.api.internal.zzbn.zzaa(Unknown Source:15)
W/Binder (18602): at com.google.firebase.auth.api.internal.zzcy.zzal(Unknown Source:0)
W/Binder (18602): at com.google.firebase.auth.api.internal.zzcy.zza(Unknown Source:0)
W/Binder (18602): at com.google.firebase.auth.api.internal.zzdb.zza(Unknown Source:47)
W/Binder (18602): at com.google.firebase.auth.api.internal.zzci.dispatchTransaction(Unknown Source:34)
W/Binder (18602): at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source:22)
W/Binder (18602): at android.os.Binder.execTransact(Binder.java:682)
W/Binder (18602): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference
W/Binder (18602): at com.google.firebase.auth.internal.zzz.zzi(Unknown Source:126)
W/Binder (18602): ... 10 more
D/SQLiteConnection(18602): DB info: open connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, flag: 0x6, FH handler: 0x73494ae600, count: 1
I/zygote64(18602): Do partial code cache collection, code=29KB, data=22KB
I/zygote64(18602): After code cache collection, code=27KB, data=22KB
I/zygote64(18602): Increasing code cache capacity to 128KB
D/SQLiteConnection(18602): DB info: close connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, FH handler: 0x73494ae600, count: 0
D/SQLiteConnection(18602): DB info: open connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, flag: 0x6, FH handler: 0x7349511ac0, count: 1
D/SQLiteConnection(18602): DB info: close connection, path: /data/user/0/com.example.something/databases/google_app_measurement_local.db, handle: 0x735654f600, FH handler: 0x7349511ac0, count: 0
以下是我呼叫匿名登录的相关代码:
Future<Null> main() async {
final FirebaseApp app = FirebaseApp.instance;
_currentUser = await _signInAnonymously();
runApp(new MyApp());
}
Future<FirebaseUser> _signInAnonymously() async {
final user = await _auth.signInAnonymously();
print('User is signed in: $user');
return user;
}
我不知道为什么它不能在我的设备上运行。我有Google Play服务,并且已更新。
我尝试使用基本的Flutter应用程序(当您按下FAB时增加一个数字)。我向它添加了Firebase匿名身份验证,没有问题。我没有得到同样的错误。如果在模拟器和我的设备上均可使用。