3.6.1 Android生命周期方法导致ANR

cocos3.6.1 Android端游戏页面调用onStopNative, onResumeNative, onPauseNative, onSurfaceDestroyedNative等生命周期方法时会导致ANR, 麻烦大佬们看下

  • 完整报错堆栈如下

    ANR_EXCEPTION
    ANR Input dispatching timed out (f681533 com.activities.NavBarActivity (server) is not responding. Waited 10003ms for MotionEvent)

    com.google.androidgamesdk.GameActivity.onStopNative(GameActivity.java)
    com.google.androidgamesdk.GameActivity.void onStop()(GameActivity.java:331)
    com.cocos.lib.CocosActivity.void onStop()(CocosActivity.java:174)
    android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1496)
    android.app.Activity.performStop(Activity.java:8536)
    android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5787)
    android.app.ActivityThread.performStopActivityInner(ActivityThread.java:5731)
    android.app.ActivityThread.handleStopActivity(ActivityThread.java:5832)
    android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:234)
    android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
    android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
    android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
    android.os.tekiapm.ProxyHandlerCallback.handleMessage(SourceFile:4)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loopOnce(Looper.java:226)
    android.os.Looper.loop(Looper.java:313)
    android.app.ActivityThread.main(ActivityThread.java:8751)
    java.lang.reflect.Method.invoke(Native method)
    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

  • 其他生命周期方法ANR

    com.google.androidgamesdk.GameActivity.onResumeNative(GameActivity.java)
    com.google.androidgamesdk.GameActivity.void onResume()(GameActivity.java:310)
    com.cocos.lib.CocosActivity.void onResume()(CocosActivity.java:161)

    com.google.androidgamesdk.GameActivity.onPauseNative(GameActivity.java)
    com.google.androidgamesdk.GameActivity.void onPause()(GameActivity.java:304)
    com.cocos.lib.CocosActivity.void onPause()(CocosActivity.java:152)

    com.google.androidgamesdk.GameActivity.onSurfaceDestroyedNative(GameActivity.java)
    com.google.androidgamesdk.GameActivity.void surfaceDestroyed(android.view.SurfaceHolder)(GameActivity.java:382)
    android.view.SurfaceView.updateSurface(SurfaceView.java:629)
    android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:257)
    android.view.View.dispatchWindowVisibilityChanged(View.java:12258)

我们也遇到了 后续有解决不?

遇到了 555

顶一下帖子。

挖, 3.7.2, 遇到了
com.google.androidgamesdk.GameActivity.onSurfaceDestroyedNative

com.google.androidgamesdk.GameActivity.onPauseNative
是重灾区

在 ./native/cocos/platform/android/java/libs/game-sdk.jar 中

@Zeinx_ 有解决办法吗?

更新一下最新情况:
通过几次发版排查, 移除 Build Config 中的 VULKAN rennder BackEnd, 线上出现此类型 ANR 的情况减少了.
对于后续遇到这个问题的朋友们, 可以尝试这个方法, 没有必要的情况下, 不要勾选 VULKAN

真的难测… 要是帮到谁的线上产品, 可以考虑请我喝饮料

更新一下:
之前的办法缓解但是没有根除

升级到了 3.8.0 仍然有这个 ANR 问题, 最近堆栈是
com.google.androidgamesdk.GameActivity.onPauseNative (GameActivity.java)

firebase 提示
This thread blocked the thread tagged as “Triggered ANR”. If this thread is tagged as both “Root Blocking” and “Triggered ANR”, then there are no other threads that block this thread.

顶一下。我们也遇到了。恶心。

顶一下 在3.8.2 也遇到了 希望解决一下

有没有人站出来 给个说法

请参考 这个 PR的修改,有结果烦请反馈,谢谢

还是有此类问题。

3.8.6问题还是存在 anr的前2位是com.google.androidgamesdk.GameActivity.onPauseNative和com.google.androidgamesdk.GameActivity.onSurfaceDestroyedNative

从3.5.2就有了,我们的产品中这类ANR占比最多

我在论坛中也多次发布这个问题,并且有很多同行也提出过类似的疑问,但似乎没人(包括官方)提供有效的解决方案,也没有看到官方花时间去分析这个问题。

通过对AGDK底层流程的分析,我最终找到了一种方法来解决这个问题。该解决方案已经在实际线上产品中得到验证,效果显著。

上上周,我还在GitHub上提交了解决 GameActivity ANR问题的issue,但官方至今没有回应(我在海外的Cocos论坛上也发帖了,但无人理会) AGDK/GameActivity ANR Bug · Issue #17841 · cocos/cocos-engine

如果对此感兴趣,可以将该解决方案应用到你的项目中,同时帮我在GitHub上评论支持:希望官方尽早将该解决方案合并到3.8.5版本中(避免每次升级引擎都需要自己合并),感谢

简单来说,这个ANR并非Cocos引擎的bug,而是Google的AGDK内部生命周期处理不合理所致(我也向Google官方提交了issue,他们并没有回避这个问题)。至于该问题深层次细节,有疑问可以通过邮件联系我。

3赞