Android add java.lang.management API

Now I have a problem with unsupported Android libraries. In fact, it does not support this API: "java.lang.management". Eclipse shows me this error:

10-25 17: 53: 03.460: java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory.

I wonder how I can add this API to support my Android application.

Any help please.

+4
source share
2 answers

This API is not part of Android and is not compatible with Android.

The API is java.lang.managementdesigned to manage and monitor the Java virtual machine. Android Dalvik VM is not a Java virtual machine.

+6

, Android 23 . , :

GarbageCollectorMXBean gb = ....
long gctime = gb.getCollectionTime();

@Jacob, . getRuntimeStat() Android. :

static {
  try {
      Class<?> debugClass = Debug.class;
      getRuntimeStat = debugClass.getDeclaredMethod(
           "getRuntimeStat", String.class);
  } catch (NoSuchMethodException x) {
      getRuntimeStat = null;
  }
}

GC - . :

String gctimestr;
try {
    gctimestr = (String) (getRuntimeStat != null ? 
         getRuntimeStat.invoke(null, "art.gc.gc-time") : null);
} catch (IllegalAccessException e) {
    gctimestr = null;
} catch (InvocationTargetException e) {
    gctimestr = null;
}

gctimestr , null. , , API.

+2

All Articles