Android ANR的解决方案

1、使用monkey进行压测,命令如下:

bash 复制代码
adb shell monkey -p com.toycloud.alphaegg.launcher --hprof --ignore-crashes --ignore-timeouts --ignore-security-exceptions --pct-syskeys 0 --throttle 100 -v -v -v 10000 > C:\Users\jjyang31\Desktop\public_apk\Monkeytest_20251103\"monkeytest_%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%-%time:~3,2%-%time:~6,2%.log"
// 100 是间隔时间 10000模拟触摸次数

2、执行完毕后通过adb bugreport 自动把anr相关的日志打包下载。

3、通过关键字搜索日志:

复制代码
	ANR in
	Reason
	"main" prio=
	Input dispatching timed out
	Broadcast of Intent
	executing service
	ContentProvider not responding
	你的包名

4、使用爱奇艺监听ANR/JAVA崩溃,添加依赖

bash 复制代码
    implementation "com.iqiyi.xcrash:xcrash-android-lib:3.1.0"
bash 复制代码
//	在Application进行初始化工作
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        String filePath = getCacheDir().getAbsolutePath() + "/xcrash";
        Log.d("MyApplication", "filePath=" + filePath);

        XCrash.InitParameters params = new XCrash.InitParameters()
                .setLogDir(filePath)
                .setJavaCallback((logPath, emergency) -> {
                    // Java 崩溃回调
                    Log.d("xCrash", "Java crash captured: " + emergency);
                    // 可以在这里上传日志到服务器
                })
                .setNativeCallback((logPath, emergency) -> {
                    // Native 崩溃回调
                    Log.d("xCrash", "Native crash captured: " + emergency);
                })
                .setAnrCallback((logPath, emergency) -> {
                    // ANR 回调
                    Log.d("xCrash", "ANR captured: " + emergency);
                });

        XCrash.init(this, params);
    }
}
相关推荐
前端老白5 分钟前
webview在微信小程序中,安卓加载失败,IOS正常加载
android·ios·微信小程序·webview
2501_937154936 分钟前
适配中兴主流机型 纯净版刷机固件技术优势合集
android·源码·源代码管理·机顶盒
2501_915106327 分钟前
用 HBuilder 上架 iOS 应用时如何管理Bundle ID、证书与描述文件
android·ios·小程序·https·uni-app·iphone·webview
TheNextByte116 分钟前
如何通过OTG或不使用OTG将文件从Android传到U盘
android
2501_9159090616 分钟前
资源文件混淆在 iOS 应用安全中的实际价值
android·安全·ios·小程序·uni-app·iphone·webview
2501_9159184117 分钟前
iOS App 性能测试中常被忽略的运行期问题
android·ios·小程序·https·uni-app·iphone·webview
天勤量化大唯粉20 分钟前
基于距离的配对交易策略:捕捉价差异常偏离的均值回归机会(天勤量化代码实现)
android·开发语言·python·算法·kotlin·开源软件·策略模式
走在路上的菜鸟22 分钟前
Android学Dart学习笔记第二十二节 类-扩展方法
android·笔记·学习·flutter
csj5023 分钟前
安卓基础之《(7)—中级控件(1)图形定制》
android
Android系统攻城狮30 分钟前
Android ALSA驱动进阶之设置访问掩码snd_pcm_access_mask_set:用法实例(九十九)
android·pcm·音频进阶·alsa驱动·android驱动