应用程序在模拟器上运行流畅但在真机上崩溃

App runs smoothly on emulators but crashes on real device

我是 android 工作室的新手,目前我正在开发一个视频通话应用程序。我的应用 运行 在 android studio 中的多个模拟器上运行顺利,但是当我尝试通过 USB 调试在真实设备 (Oppo f9 pro) 上 运行 它时,应用可以安装但立即崩溃。

logcat 中有几个错误。我搜索了 google 上的每个错误,但没有找到任何解决方案。以下是logcat.

中的错误
2021-12-14 20:23:12.541 2314-2314/? E/com.ahmad.nexo: Unknown bits set in runtime_flags: 0x8000
2021-12-14 20:23:14.998 2314-2314/com.ahmad.nexon E/ANR_LOG: >>> msg's executing time is too long
2021-12-14 20:23:14.998 2314-2314/com.ahmad.nexon E/ANR_LOG: Blocked msg = { when=-2s417ms what=110 target=android.app.ActivityThread$H obj=AppBindData{appInfo=ApplicationInfo{cc71d2b com.ahmad.nexon}} } , cost  = 2390 ms
2021-12-14 20:23:14.998 2314-2314/com.ahmad.nexon E/ANR_LOG: >>>Current msg List is:
2021-12-14 20:23:14.998 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <1>  = { when=-2s413ms what=159 target=android.app.ActivityThread$H obj=ClientTransaction hashCode, mActivityToken = android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.998 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <2>  = { when=-2s411ms what=159 target=android.app.ActivityThread$H obj=ClientTransaction hashCode, mActivityToken = android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.998 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <3>  = { when=-2s396ms what=159 target=android.app.ActivityThread$H obj=ClientTransaction hashCode, mActivityToken = android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <4>  = { when=-2s394ms what=159 target=android.app.ActivityThread$H obj=ClientTransaction hashCode, mActivityToken = android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <5>  = { when=-2s392ms what=9999 target=android.app.ActivityThread$H }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <6>  = { when=-2s353ms what=149 target=android.app.ActivityThread$H obj=android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <7>  = { when=-2s348ms what=0 target=android.app.ActivityThread$H callback=com.android.internal.util.function.pooled.PooledLambdaImpl }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <8>  = { when=-1s886ms what=159 target=android.app.ActivityThread$H obj=ClientTransaction hashCode, mActivityToken = android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <9>  = { when=-1s886ms what=137 target=android.app.ActivityThread$H arg1=1 obj=android.os.BinderProxy@5ecb588 }
2021-12-14 20:23:14.999 2314-2314/com.ahmad.nexon E/ANR_LOG: Current msg <10>  = { when=+980ms what=131 target=android.app.ActivityThread$H obj=android.app.ActivityThread$ProviderRefCount@448eb21 }
2021-12-14 20:23:15.000 2314-2314/com.ahmad.nexon E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<

有很多情况会导致您的应用崩溃。有些原因很明显,例如检查空值或空字符串,但其他原因则更为微妙,例如将无效参数传递给 API 甚至复杂的多线程交互。 检查此 Link

  1. Najib Raihan 是正确的:首先要检查的是您设备上的 android 版本,而不是您的模拟器。

  2. 即使版本匹配,也完全有可能一个看起来“工作”,另一个“崩溃”。仅仅因为一个或另一个没有“崩溃”,并不意味着您的代码是“正确的”。您绝对需要密切注意编译应用程序时 Studio 给您的警告 Android。

  3. 我在您显示的 logcat 中没有看到任何“致命错误”:您需要仔细观察。特别是,“runtime_flags 中设置的未知位:0x8000”错误 不是 您的应用程序崩溃的原因。看这里:

有根据的猜测:

我怀疑您的设备可能 运行 是 Android 的较新版本,具有额外的“安全限制”。这有时会导致应用程序终止 - 有时甚至会在没有明确 logcat 消息的情况下终止。

建议:

计划 A:

将故障设备插入您的 USB 端口(正如您所做的那样),确保 Logcat 在 A/S 之前 [=39] 是 运行 =] 你启动你的应用程序,然后点击“调试”(而不是“运行”,我相信你可能已经在这样做了)。在 LogCat and/or A/S 调试器中查找“致命错误”。

计划 B:

如果它仍然没有给你一个像样的错误信息,那么在你的应用程序中设置断点(从你的第一个屏幕上的第一个显示开始)并“分而治之”直到你找到失败点.

问题出在角度属性上。例如,如果您使用 112 或 100 或 130 等的角度,这将使您的应用程序崩溃。总是在 45 上使用可分割的角度,例如 android:angle="90" android:angle="180" 等等