启动到物理设备时出现黑屏

Getting blank screen when launching to a physical device

我的应用程序在我的模拟器 (Google Pixel 2) 上 运行 非常好,但是当我尝试将应用程序启动到物理设备 (Galaxy Note 20) 时,我只是出现白屏,物理设备比模拟器更新得多可能会出现问题。 我试过了:

flutter upgrade 
flutter clean 

并将 minSDK 更改为 23 而不是 16。我也尝试将依赖项升级到较新的版本,但由于不兼容问题,我不得不将它们重置回旧版本。

启动模拟器时我得到这个:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:54695/lfhRZFuIGMw=/ws
Syncing files to device Android SDK built for x86...
D/EGL_emulation(21851): eglMakeCurrent: 0xebea1000: ver 3 0 (tinfo 0xcc025380)
D/eglCodecCommon(21851): setVertexArrayObject: set vao to 0 (0) 1 0

当启动到物理设备时,这是我得到的:

Launching lib\main.dart on SM N985F in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:54580/fefT1rs2LOk=/ws
Syncing files to device SM N985F...
E/flutter (22977): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null.
E/flutter (22977): Receiver: null
E/flutter (22977): Tried calling: length
E/flutter (22977): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (22977): #1      _parseJson (dart:convert-patch/convert_patch.dart:39:28)
E/flutter (22977): #2      JsonDecoder.convert (dart:convert/json.dart:506:36)
E/flutter (22977): #3      JsonCodec.decode (dart:convert/json.dart:157:41)
E/flutter (22977): #4      jsonDecode (dart:convert/json.dart:96:10)
E/flutter (22977): #5      getList (package:realtime_test/main.dart:27:30)
E/flutter (22977): <asynchronous suspension>
E/flutter (22977): #6      main (package:realtime_test/main.dart:16:3)
E/flutter (22977): <asynchronous suspension>
E/flutter (22977): 
I/ViewRootImpl@46a8966[MainActivity](22977): ViewPostIme pointer 0
I/ViewRootImpl@46a8966[MainActivity](22977): MSG_WINDOW_FOCUS_CHANGED 0 1
I/SurfaceControl(22977): release : mNativeObject = 476773762736 - Surface(name=Surface(name=a38c4 InputMethod)/@0x7a23a73 - animation-leash)/@0xa41f0a1 / android.view.-$$Lambda$Rl1VZmNJ0VZDLK0BAbaVGis0rrA.accept:2 android.view.InsetsSourceControl.release:170 android.view.InsetsSourceConsumer.setControl:202 android.view.ImeInsetsSourceConsumer.setControl:154 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773762736]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773762736]
I/SurfaceControl(22977): release : mNativeObject = 476773765760 - Surface(name=Surface(name=2a9e95b NavigationBar0)/@0x87e7f82 - animation-leash)/@0x2190368 / android.view.-$$Lambda$Rl1VZmNJ0VZDLK0BAbaVGis0rrA.accept:2 android.view.InsetsSourceControl.release:170 android.view.InsetsSourceConsumer.setControl:202 android.view.InsetsController.onControlsChanged:833 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773765760]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773765760]
I/SurfaceControl(22977): release : mNativeObject = 476773740672 - Surface(name=Surface(name=6106940 StatusBar)/@0xd1b68b8 - animation-leash)/@0xe205381 / android.view.-$$Lambda$Rl1VZmNJ0VZDLK0BAbaVGis0rrA.accept:2 android.view.InsetsSourceControl.release:170 android.view.InsetsSourceConsumer.setControl:202 android.view.InsetsController.onControlsChanged:833 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773740672]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773740672]
D/InputTransport(22977): Input channel destroyed: 'ClientS', fd=122
I/SurfaceControl(22977): release : mNativeObject = 476773811120 - Surface(name=Surface(name=a38c4 InputMethod)/@0x7a23a73 - animation-leash)/@0x2fda6bd / android.view.-$$Lambda$Rl1VZmNJ0VZDLK0BAbaVGis0rrA.accept:2 android.view.InsetsSourceControl.release:170 android.view.InsetsSourceConsumer.setControl:202 android.view.ImeInsetsSourceConsumer.setControl:154 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773811120]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773811120]
I/SurfaceView(22977): onWindowVisibilityChanged(8) false io.flutter.embedding.android.FlutterSurfaceView{a0c34fd V.E...... ........ 0,0-1440,3035} of ViewRootImpl@46a8966[MainActivity]
I/SurfaceView(22977): surfaceDestroyed callback.size 1 #2 io.flutter.embedding.android.FlutterSurfaceView{a0c34fd V.E...... ........ 0,0-1440,3035}
I/mali_egl(22977): eglDestroySurface() in
I/mali_winsys(22977): delete_surface() [1440x3035] return
I/mali_egl(22977): eglDestroySurface() out
W/libEGL  (22977): EGLNativeWindowType 0x7021f7c4a0 disconnect failed
D/SurfaceControl(22977): hide : mNativeObject = 477310781072 - sc.mNativeObject = 476773737760 - Surface(name=SurfaceView - com.example.realtime_test/com.example.realtime_test.MainActivity@a0c34fd@0)/@0x4db9fa2
D/SurfaceControl(22977): nativeSetFlags Done : Surface(name=SurfaceView - com.example.realtime_test/com.example.realtime_test.MainActivity@a0c34fd@0)/@0x4db9fa2
I/SurfaceView(22977): remove() from RT android.view.SurfaceView@1fbc4b2 Surface(name=SurfaceView - com.example.realtime_test/com.example.realtime_test.MainActivity@a0c34fd@0)/@0x4db9fa2
I/SurfaceControl(22977): release : mNativeObject = 476773737760 - Surface(name=SurfaceView - com.example.realtime_test/com.example.realtime_test.MainActivity@a0c34fd@0)/@0x4db9fa2 / android.view.SurfaceControl$Transaction.remove:3449 android.view.SurfaceView.positionLost:1561 android.graphics.RenderNode$CompositePositionUpdateListener.positionLost:313 <bottom of call stack> 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773737760]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773737760]
I/SurfaceControl(22977): release : mNativeObject = 476773742576 - Surface(name=Background for -SurfaceView - com.example.realtime_test/com.example.realtime_test.MainActivity@a0c34fd@0)/@0x1cd2c03 / android.view.SurfaceControl$Transaction.remove:3449 android.view.SurfaceView.positionLost:1562 android.graphics.RenderNode$CompositePositionUpdateListener.positionLost:313 <bottom of call stack> 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773742576]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773742576]
I/mali_egl(22977): eglDestroySurface() in
I/mali_winsys(22977): delete_surface() [1440x3088] return
I/mali_egl(22977): eglDestroySurface() out
W/libEGL  (22977): EGLNativeWindowType 0x7021f7a290 disconnect failed
I/SurfaceControl(22977): release : mNativeObject = 476773781888 - Surface(name=null)/@0x516d780 / android.view.SurfaceControl.assignNativeObject:567 android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1777 android.view.ViewRootImpl.relayoutWindow:8953 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773781888]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773781888]
I/SurfaceControl(22977): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x516d780 / android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1777 android.view.ViewRootImpl.relayoutWindow:8953 android.view.ViewRootImpl.performTraversals:3312 android.view.ViewRootImpl.doTraversal:2575 android.view.ViewRootImpl$TraversalRunnable.run:9910 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995 
I/SurfaceControl(22977): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8186ac0 / android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1787 android.view.ViewRootImpl.relayoutWindow:8953 android.view.ViewRootImpl.performTraversals:3312 android.view.ViewRootImpl.doTraversal:2575 android.view.ViewRootImpl$TraversalRunnable.run:9910 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995 
I/SurfaceControl(22977): release : mNativeObject = 476773737200 - Surface(name=Bounds for - com.example.realtime_test/com.example.realtime_test.MainActivity@0)/@0xd62f1b9 / android.view.ViewRootImpl.destroySurface:2437 android.view.ViewRootImpl.relayoutWindow:8990 android.view.ViewRootImpl.performTraversals:3312 android.view.ViewRootImpl.doTraversal:2575 
I/SurfaceControl(22977): nativeRelease nativeObject s[476773737200]
I/SurfaceControl(22977): nativeRelease nativeObject e[476773737200]
I/ViewRootImpl@46a8966[MainActivity](22977): Relayout returned: old=(0,0,1440,3088) new=(0,0,1440,3088) req=(1440,3088)8 dur=6 res=0x5 s={false 0} ch=true fn=2
I/SurfaceView(22977): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{a0c34fd V.E...... ........ 0,0-1440,3035} of ViewRootImpl@46a8966[MainActivity]
I/ViewRootImpl@46a8966[MainActivity](22977): stopped(true) old=false

所以很明显出了问题,但我不知道是什么问题。

  • 您出现白屏是因为您的应用无法通过您在启动时执行的初始功能。

  • 错误信息说getter length called on null,然后它 在第 #27 行中断你的 main.dart。进一步阅读 错误,你正在调用 jsonDecode,但它没有收到任何东西, 导致您的应用程序崩溃并且无法加载主页。

  • 不是 技术上崩溃了,但它正在等待第 27 行的逻辑 完成,但还没有完成。因为它说 getter length was called on null 很可能也意味着您正在 for 循环中执行逻辑,或者检查是否有 isEmptyisNotEmpty,当检查这些属性时,iterable 它试图在调用此函数时检查是否为空。

  • 首先仔细检查,这很可能是由于您在使用模拟器时遇到的错误,然后修复它并让模拟器工作,但没有解决您的问题使用全新安装的新用户,例如您的物理设备。

  • 如果您从数据库中获取数据,并在模拟器上开发时使用了初始虚拟数据,而忘记为新设备添加该数据,这应该可以解决您的问题,我会开始寻找那里。

  • 另一件事要记住,当您的应用成功编译和构建时,您的问题不在于依赖项或 SDK 版本或与您的构建相关的其他问题 gradle。你的错误是这样 √ Built build\app.... ,所以问题不是由构建时故障引起的,而是运行时错误。