首页 > 解决方案 > 启动到物理设备时出现黑屏

问题描述

我的应用程序在我的模拟器(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$2@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$2.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$2.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

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

标签: flutterdartlaunch

解决方案


  • 您正在显示白屏,因为您的应用程序无法超越您在启动时执行的初始功能。

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

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

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

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

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


推荐阅读