Cordova Android应用频繁崩溃,是否因cordova-plugin-printer导致?
PrintManager.removePrintJobStateChangeListener - Is katzer's cordova-plugin-printer the Cause? I'm developing a Cordova Android app that's experiencing a large number of crashes. With limited Android development experience, I noticed that all crash backtraces include this line:
pc 0000000001053a38 /system/framework/arm64/boot-framework.oat (android.print.PrintManager.removePrintJobStateChangeListener+200)I'm using katzer's cordova-plugin-printer plugin to handle cross-platform (Android/iOS) native printing, and this plugin hasn't been updated in over 8 months. Can I confirm that this plugin is the cause of the crashes?
Here's the full crash backtrace:
backtrace: #00 pc 000000000006ca30 /system/lib64/libc.so (tgkill+8) #01 pc 0000000000069eb8 /system/lib64/libc.so (pthread_kill+64) #02 pc 0000000000024198 /system/lib64/libc.so (raise+24) #03 pc 000000000001c9b0 /system/lib64/libc.so (abort+52) #04 pc 0000000000435c2c /system/lib64/libart.so (_ZN3art7Runtime5AbortEv+352) #05 pc 00000000000e524c /system/lib64/libart.so (_ZN3art10LogMessageD2Ev+1204) #06 pc 00000000004c6c60 /system/lib64/libart.so (_ZN3art28InvokeProxyInvocationHandlerERNS_33ScopedObjectAccessAlreadyRunnableEPKcP8_jobjectS5_RNSt3__16vectorI6jvalueNS6_9allocatorIS8_EEEE+2960) #07 pc 00000000005520a0 /system/lib64/libart.so (artQuickProxyInvokeHandler+1040) #08 pc 00000000000db0ac /system/lib64/libart.so (art_quick_proxy_invoke_handler+76) #09 pc 0000000002cb0420 /system/framework/arm64/boot-framework.oat (android.util.ArrayMap.indexOf+204) #10 pc 0000000002cb0704 /system/framework/arm64/boot-framework.oat (android.util.ArrayMap.indexOfKey+160) #11 pc 0000000002cb16b4 /system/framework/arm64/boot-framework.oat (android.util.ArrayMap.remove+48) #12 pc 0000000002a1f194 /system/framework/arm64/boot-framework.oat (android.print.PrintManager.removePrintJobStateChangeListener+176)
Answer
Based on your crash backtrace and the plugin's status, it’s highly likely that katzer’s cordova-plugin-printer is the root cause of these crashes. Let’s break this down:
1. The Crash Points Directly to Print Listener Management Issues
The stack trace shows the crash happens when PrintManager.removePrintJobStateChangeListener tries to remove an entry from an ArrayMap (lines #9-12). This usually stems from one of a few common bugs in listener handling:
- Attempting to remove a listener that was never registered, or was already removed
- Accessing the PrintManager or listener collection from a non-main thread (Android requires all UI/PrintManager-related operations to run on the main thread)
- A memory leak where the listener is retained after the app’s activity context is destroyed, leading to invalid references when removal is attempted
2. The Plugin's Stagnation Makes It a Prime Culprit
Since the plugin hasn’t been updated in over 8 months, it’s probable that:
- It doesn’t account for changes to Android’s PrintManager behavior in newer OS versions (like stricter thread enforcement or modified listener lifecycle rules)
- Its implementation of adding/removing print job state listeners has an unaddressed bug that only surfaces under real-world conditions (like rapid app state changes or repeated print operations)
3. Steps to Confirm & Fix the Issue
- Dig into the plugin’s Android source code: Locate where
addPrintJobStateChangeListenerandremovePrintJobStateChangeListenerare called. Check if:- Listeners are reliably removed (e.g., in the plugin’s
destroyoronPausehandlers) - All PrintManager interactions are wrapped to run on the main thread (using
cordova.getActivity().runOnUiThread(...)) - There are guard clauses to prevent removing unregistered listeners
- Listeners are reliably removed (e.g., in the plugin’s
- Reproduce the crash in a minimal test app: Build a simple Cordova app that only uses the plugin’s print features, then simulate the actions that trigger crashes (e.g., print, exit the app, repeat) to confirm the plugin is the source
- Temporary workaround: If you can’t switch plugins immediately, modify the plugin’s code to:
- Wrap all listener operations in main thread calls
- Add null checks and existence checks before attempting to remove listeners
- Switch to a maintained alternative: If the bug is unfixable or the plugin is abandoned, look for actively updated Cordova print plugins that support modern Android versions properly
内容的提问来源于stack exchange,提问作者Ray A

