Reputation: 1423
Now I have a problem with Android non-supported 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 be supported by my android application.
Any help please.
Upvotes: 3
Views: 5477
Reputation:
It seems that with Android Version 23, situation has slightly improved. For example I found a replacement for:
GarbageCollectorMXBean gb = ....
long gctime = gb.getCollectionTime();
Thanks to @Jacob, I am now using this code. First the getRuntimeStat()
method is not available in all android versions. So I am doing some reflection first:
static {
try {
Class<?> debugClass = Debug.class;
getRuntimeStat = debugClass.getDeclaredMethod(
"getRuntimeStat", String.class);
} catch (NoSuchMethodException x) {
getRuntimeStat = null;
}
}
Retrieving the GC time is then a matter of calling the method handle, with the correct property name. I am currently using this property name:
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;
}
The gctimestr
can then be converted to a long value, if its non-null. On the other hand if its null the statistics is not available, through this API.
Upvotes: 2
Reputation: 67249
That API is not a part of Android, and is not compatible with Android.
The java.lang.management
API is for managing and monitoring the Java VM. Android's Dalvik VM is not a Java VM.
Upvotes: 8