解决MediaMetadataRetriever.finalize()超时问题
文章目录
- 问题
- 解决方案
- 1.忽略TimeoutException异常
- 2.接入Booster插件
- 参考
问题
媒体对象关闭超时
Caused by: java.util.concurrent.TimeoutException:
android.media.MediaMetadataRetriever.finalize() timed out after 10
seconds
解决方案
1.忽略TimeoutException异常
滴滴出行安卓端 finalize time out 方案
总结:
- 手动修改finialize()超时时间
- 不可行,超时时间为静态常量,在编译期就会被替换成常量,运行期修改不生效。
- 手动停掉FinalizerWatchdogDaeman线程
- 接入 滴滴Booster质量优化框架
- 忽略超时异常,如下:
1public class RuntimeInit {
2 ...
3 private static class UncaughtHandler implements Thread.UncaughtExceptionHandler {
4 public void uncaughtException(Thread t, Throwable e) {
5 try {
6 ...
7 // Bring up crash dialog, wait for it to be dismissed 展示APP停止运行对话框
8 ActivityManagerNative.getDefault().handleApplicationCrash(
9 mApplicationObject, new ApplicationErrorReport.CrashInfo(e));
10 } catch (Throwable t2) {
11 ...
12 } finally {
13 // Try everything to make sure this process goes away.
14 Process.killProcess(Process.myPid()); //退出进程
15 System.exit(10);
16 }
17 }
18 }
19
20 private static final void commonInit() {
21 ...
22 /* set default handler; this applies to all threads in the VM */
23 Thread.setDefaultUncaughtExceptionHandler(new UncaughtHandler());
24 ...
25 }
26}
主动忽略FinializerWatchdogDaemon出现TimeoutException的异常,阻断UncaughtExceptionHandler链式调用,减少用户影响。
2.接入Booster插件
核心思路 在应用启动后,停掉 FinalizerWatchdogDaemon 线程
Booster指南
Booster仓库
-
接入版本
-
在根目录 build.gradle 中接入插件
buildscript {
ext.booster_version = '5.0.0'
dependencies {
classpath "com.didiglobal.booster:booster-gradle-plugin:$booster_version" // ①
// ② figure out the features you really need, then choose the right module for integration
// ② 弄清楚真正需要的特性,然后从下面的模块列表中选择正确的模块进行集成
classpath "com.didiglobal.booster:booster-transform-finalizer-watchdog-daemon:$booster_version"
classpath "com.didiglobal.booster:booster-task-analyser:$booster_version"
}
}
- 在模块中引入,尽量放在application下面
apply plugin: 'com.android.application'
apply plugin: 'com.didiglobal.booster'
- 确认Booster是否启用
./gradlew assembleDebug --dry-run
搜索关键字transformClassesWithBoosterForDebug,说明已经启用
参考
深入理解Booster(一)-gradle插件开发如何兼容不同的agp版本