flutter_boost icon indicating copy to clipboard operation
flutter_boost copied to clipboard

connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null. com.idlefish.flutterboost.containers.FlutterBoostActivity.C(FlutterBoostActivity.java:163)

Open xujiangithub opened this issue 2 years ago • 9 comments

当flutter端存在内存泄漏的时候,发现的这个问题。有监听器在页面dispose后调用了setState;

由于flutterboost中FlutterTextureHooker存在反射调用FlutterTextureView;而FlutterTextureView类被混淆而导致反射逻辑失败,导致FlutterTextureView类的attachToRenderer方法中connectSurfaceToRenderer被执行,而此时绘制层已经为空,所以报错:connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null

xujiangithub avatar Apr 01 '22 09:04 xujiangithub

需要在混淆文件中添加 -keep class io.flutter.embedding.android.FlutterTextureView { *; }

xujiangithub avatar Apr 01 '22 09:04 xujiangithub

需要在混淆文件中添加 -keep class io.flutter.embedding.android.FlutterTextureView { *; }

加混淆应该在你对应项目工程的 proguard-rules 文件进行添加,不过这个问题应该还是低版本系统纹理被异常释放的问题。方便的话提供下可复现的demo ?

dengzq avatar May 23 '22 10:05 dengzq

在开发时候,对于aar包内的反射类,需要在aar中进行混淆的keep配置吧,不然上层业务是有可能会遗漏的 。demo无法提供,不好意思哈

------------------ 原始邮件 ------------------ 发件人: "alibaba/flutter_boost" @.>; 发送时间: 2022年5月23日(星期一) 晚上6:47 @.>; @.@.>; 主题: Re: [alibaba/flutter_boost] connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null. com.idlefish.flutterboost.containers.FlutterBoostActivity.C(FlutterBoostActivity.java:163) (Issue #1621)

需要在混淆文件中添加 -keep class io.flutter.embedding.android.FlutterTextureView { *; }

加混淆应该在你对应项目工程的 proguard-rules 文件进行添加,不过这个问题应该还是低版本系统纹理被异常释放的问题。方便的话提供下可复现的demo ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

xujiangithub avatar May 24 '22 03:05 xujiangithub

@dengzq 你好 我这边低版本的也出现类似的问题

 # 崩溃设备信息:Android-6.0.1 Oppo R9s Plus
 # 闲鱼 https://github.com/alibaba/flutter_boost
  flutter_boost:
    git:
      url: 'https://github.com/alibaba/flutter_boost.git'
      ref: 'v3.0-null-safety-preview.16'
  • 崩溃堆栈(目前崩溃平台的mapping解析有问题 下面我将会对照mapping文件简单解释一下)
Thread Name:'main'
Back traces starts.
java.lang.RuntimeException: Unable to resume activity {com.chs.cxrbusinessclient/com.chs.mobile.flutter_container.CaiFlutterBoostActivity}: java.lang.IllegalStateException: connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null.
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3311)
	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3352)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538)
	at com.chs.mobile.caicommonkit.log.instrumentation.ProxyHandlerCallback.handleMessage(ProxyHandlerCallback.java:4)
	at android.os.Handler.dispatchMessage(Handler.java:98)
	at android.os.Looper.loop(Looper.java:179)
	at android.app.ActivityThread.main(ActivityThread.java:5769)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:676)
Caused by: java.lang.IllegalStateException: connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null.
	at io.flutter.embedding.android.FlutterTextureView.i(FlutterTextureView.java:4)
	at io.flutter.embedding.android.FlutterTextureView.a(FlutterTextureView.java:9)
        at io.flutter.embedding.android.FlutterView.k(FlutterView.java:10)
	at com.idlefish.flutterboost.containers.FlutterBoostActivity.t(FlutterBoostActivity.java:6)
	at com.idlefish.flutterboost.containers.FlutterBoostActivity.onResume(FlutterBoostActivity.java:10)
	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1259)
	at android.app.Activity.performResume(Activity.java:6573)
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3300)
	... 9 more
Back traces end.

~~~

  • 流程解释
    • FlutterBoostActivity->onResume()
    • FlutterBoostActivity->performAttach()
    • FlutterView->attachToFlutterEngine()
    • FlutterTextureView->attachToRenderer()
    • FlutterTextureView->connectSurfaceToRenderer()
      if (flutterRenderer == null || getSurfaceTexture() == null) {
      throw new IllegalStateException(
         "connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null.");
      }
      

hy20160705 avatar Jun 01 '22 06:06 hy20160705

retore surface的时候暴力地判断了6.0及以下系统版本,有可能这个6.0.1系统的机型也有相同的问题。可以尝试的方案:本地拉取你要的 boost 分支,修改 flutterTextureHooker 里面的判断6.0的逻辑,拿当前手机再试一下。

dengzq avatar Jun 12 '22 02:06 dengzq

如果有可复现的demo也麻烦给一下。

dengzq avatar Jun 12 '22 02:06 dengzq

在6.0的系统首页任何一个fragment打开一个独立的flutter按返回就报这个错,用flutter页面打开flutter页面按返回没问题

gyh124 avatar Jun 17 '22 05:06 gyh124

需要在混淆文件中添加 -keep class io.flutter.embedding.android.FlutterTextureView { *; }

请问一下这里只加这个就ok了么?这个问题有没有根本的解决方案呢?

JunhuaLin avatar Aug 15 '22 06:08 JunhuaLin

加了就可以了,因为我公司fork了flutterboost的代码,所以可以直接加在这。如果你没有fork的话,添加的地方就不好选了。可能flutterboost在打aar的时候,已经被混淆掉了(这个我没看,如果还没有混淆的话,那你可以在原生壳里,keep一下)

flutterboost其实还会有一些其他的问题,所以我公司这边是fork了代码,然后经常同步一下新的hotfix

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月15日(星期一) 下午2:48 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [alibaba/flutter_boost] connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null. com.idlefish.flutterboost.containers.FlutterBoostActivity.C(FlutterBoostActivity.java:163) (Issue #1621)

需要在混淆文件中添加 -keep class io.flutter.embedding.android.FlutterTextureView { *; }

请问一下这里只加这个就ok了么?这个问题有没有根本的解决方案呢?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

xujiangithub avatar Aug 15 '22 08:08 xujiangithub