我有一个 Android Instrumented 测试,我尝试启动我的应用程序并执行以下操作:
open class MyApplication : Application() {
...
override fun onCreate() {
super.onCreate()
initialiseLogging()
initialiseStrictMode()
initialiseDependencyGraph()
}
private fun initialiseDependencyGraph() {
applicationComponent = createApplicationComponent()
applicationComponent.inject(this)
}
...
private fun initialiseStrictMode() {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyDeath()
.build())
}
}
当我在 Firebase 上运行它们时,所有测试在大多数设备上都通过了,除了Huawei Mate 9 with Nougat (Android 7.0 with API 24)。当我对此设备运行测试时,出现以下错误:
02-19 15:25:13.822: E/InstrumentationResultPrinter(10431): Failed to mark test No Tests as finished after process crash
02-19 15:25:13.822: E/MonitoringInstr(10431): Exception encountered by: au.com.dius.powersensor.platform.TestApp@2b58cb5. Dumping thread state to outputs and pining for the fjords.
02-19 15:25:13.822: E/MonitoringInstr(10431): android.os.StrictMode$StrictModeViolation: policy=262151 violation=2
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.StrictMode.executeDeathPenalty(StrictMode.java:1556)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.StrictMode.-wrap3(StrictMode.java)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.StrictMode$AndroidBlockGuardPolicy.handleViolation(StrictMode.java:1549)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.StrictMode$AndroidBlockGuardPolicy.handleViolationWithTimingAttempt(StrictMode.java:1367)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.StrictMode$AndroidBlockGuardPolicy.startHandlingViolationException(StrictMode.java:1337)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1306)
02-19 15:25:13.822: E/MonitoringInstr(10431): at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:249)
02-19 15:25:13.822: E/MonitoringInstr(10431): at java.io.File.exists(File.java:780)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.graphics.Typeface.initHwFontConfig(Typeface.java:295)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.graphics.Typeface.updateFont(Typeface.java:361)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.graphics.Typeface.loadSystemFonts(Typeface.java:444)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5671)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.app.ActivityThread.-wrap2(ActivityThread.java)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.Handler.dispatchMessage(Handler.java:102)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.os.Looper.loop(Looper.java:156)
02-19 15:25:13.822: E/MonitoringInstr(10431): at android.app.ActivityThread.main(ActivityThread.java:6524)
02-19 15:25:13.822: E/MonitoringInstr(10431): at java.lang.reflect.Method.invoke(Native Method)
02-19 15:25:13.822: E/MonitoringInstr(10431): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
02-19 15:25:13.822: E/MonitoringInstr(10431): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
我似乎很清楚StricMode
已经发现了一个奇怪的错误,即ActivityThread
尝试通过使用主线程从磁盘加载字体系统来初始化字体系统。
没有任何在线提供此错误的解决方案,而且我的测试仅针对此特定设备失败似乎很奇怪。
任何人对如何解决此问题或可能导致此问题的原因有任何想法?