<p dir="auto"><a href="https://codelabs.developers.google.com/codelabs/first-flutter-app-pt2/#0" rel="nofollow">https://codelabs.developers.google.com/codelabs/first-flutter-app-pt2/#0</a> has lots of <code class="notranslate">new</code> keyword. It can be removed since newer Dart versions don't require it :)</p>
<p dir="auto">I have a Flutter/Firebase application that works on an Android emulator, but not on a real device (HTC 10 with Android 8.0). It fails with a NullPointerException from inside the Firebase auth code, but the stack trace doesn't include the location in my app's code where the call originated from.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    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"><pre lang="log" class="notranslate"><code class="notranslate">    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
</code></pre></div>
<p dir="auto">Here's the relevant code where I'm calling the anonymous sign in:</p>
<div class="highlight highlight-source-dart notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    Future&lt;Null&gt; main() async {
      final FirebaseApp app = FirebaseApp.instance;
      _currentUser = await _signInAnonymously();
      runApp(new MyApp());
    }

    Future&lt;FirebaseUser&gt; _signInAnonymously() async {
      final user = await _auth.signInAnonymously();
      print('User is signed in: $user');
      return user;
    }"><pre class="notranslate">    <span class="pl-c1">Future</span>&lt;<span class="pl-c1">Null</span>&gt; <span class="pl-en">main</span>() <span class="pl-k">async</span> {
      <span class="pl-k">final</span> <span class="pl-c1">FirebaseApp</span> app <span class="pl-k">=</span> <span class="pl-c1">FirebaseApp</span>.instance;
      _currentUser <span class="pl-k">=</span> <span class="pl-k">await</span> <span class="pl-en">_signInAnonymously</span>();
      <span class="pl-en">runApp</span>(<span class="pl-k">new</span> <span class="pl-c1">MyApp</span>());
    }

    <span class="pl-c1">Future</span>&lt;<span class="pl-c1">FirebaseUser</span>&gt; <span class="pl-en">_signInAnonymously</span>() <span class="pl-k">async</span> {
      <span class="pl-k">final</span> user <span class="pl-k">=</span> <span class="pl-k">await</span> _auth.<span class="pl-en">signInAnonymously</span>();
      <span class="pl-en">print</span>(<span class="pl-s">'User is signed in: $<span class="pl-v">user</span>'</span>);
      <span class="pl-k">return</span> user;
    }</pre></div>
<p dir="auto">I have no idea why it isn't working on my device. I have Google Play Services and it's updated.</p>
<p dir="auto">I tried with the basic Flutter app (increment a number when you hit the FAB). I added Firebase Anonymous Auth to it, and no problems. I didn't get the same error. If worked on both the emulator and my device.</p>