25

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)
mattfred
  • 2,689
  • 1
  • 22
  • 38
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
  • Well, ANR is usually associated with "application not responding", the error message given when tying up the main application thread for a long time. The fact that this is occurring on a binder thread suggests that perhaps `ANRManagerProxy` is the watcher for tying up key threads, including the pool of Binder IPC threads. Make sure you're not tying up the main application thread or any Binder threads (e.g., remote services with AIDL). However, I haven't a clue as to why some Android builds are missing this class and giving you the `NoClassDefFoundError`. – CommonsWare Mar 26 '15 at 23:51
  • Does this happen only on one specific device ? – Jonas Czech Mar 27 '15 at 12:43
  • @JonasCz Can't say for sure, but I think, yes. – Alexander Kulyakhtin Mar 27 '15 at 17:57
  • Did you get this resolved? – Jared Burrows Jun 21 '15 at 23:16
  • I had similar "NoClassDefFoundError"s but fixed them by taking out some libraries I no longer needed and rearranging the order of libraries. I never found out exactly why - it felt like black magic – Martin Aug 17 '15 at 21:09
  • 2
    We only saw this once on a Lenovo A316i running 4.2.2. – Dunc Oct 05 '15 at 09:58
  • @Dunc, I see it on a Lenovo A316i too – Alexey Subbota Feb 04 '17 at 12:01

2 Answers2

13

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.

Kane O'Riley
  • 2,482
  • 2
  • 18
  • 27
  • 3
    wow, such a good "feature". "- Hey man, should we remove random classes from the framework? - Sure bro, that's an awesome idea" – Gintas_ May 08 '16 at 11:47
4

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();
}
Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
tpcz
  • 186
  • 1
  • 4