问题
Does anyone know why this happens? I see this crash reported by my app but I have no idea what it is.
java.lang.NoClassDefFoundError: android.app.ANRManagerProxy
Thread: Binder_3, Exception: java.lang.NoClassDefFoundError: android.app.ANRManagerProxy
at android.app.ANRManagerNative.asInterface(ANRManagerNative.java:30)
at android.app.ANRManagerNative$1.create(ANRManagerNative.java:94)
at android.app.ANRManagerNative$1.create(ANRManagerNative.java:88)
at android.util.Singleton.get(Singleton.java:34) at android.app.ANRManagerNative.getDefault(ANRManagerNative.java:37)
at android.os.MessageLogger.dump(MessageLogger.java:253)
at android.app.ANRAppManager.dumpMessageHistory(SourceFile:38)
at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1176)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:609)
at android.os.Binder.execTransact(Binder.java:351)
at dalvik.system.NativeStart.run(Native Method)
回答1:
This error can be seen on a small group of devices (I don't have a list, but they tend to be no-name brands) whose firmware developers, for unknown reasons, removed the ANRManagerProxy
from the device framework (I confirmed this by hunting down a firmware and decompiling it myself).
The best you can do is try to hunt down any possible code which could be locking up the thread and causing the device to become nonresponsive, and try to use an AsyncTask
or similar to run the code asynchronously and avoid the ANR. The devices in question are always low end, and so your code will take longer to run and have a greater chance of causing this to happen.
I'd suggest Hugo as a great library for debugging method execution times, in order to narrow your focus on where the most time is being spent. This will help improve your code for all users, as well as reducing the risk of the crash in question.
回答2:
This happens, because
- your app id doing some heavy work in main (GUI) thread
and
- target device has messed up firmware
Here is a list of devices, where I experienced more frequently the bug - so not only low end devices, be careful you will ignore it :-)
Lenovo A316i, N5i, V769M , G3 orro, V5, G3, X-2, F-G906, Z350, V10, G910, EVOLVEO StrongPhone D2, A70C, G9006, V13, C3000, n968, SM-T322, H9503, GT-H9503, S5, F1, Lenovo TP-6000, Galaxy Tab SM-T700C ...
Only thing you can do about this is to make your app responsive. Best way to do so is to use during development and testing Strict Mode, i.e., to do something like this:
public void onCreate() {
if (DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
super.onCreate();
}
来源:https://stackoverflow.com/questions/29289641/noclassdeffounderror-android-app-anrmanagerproxy