1

Is there is was to find out what android runtime version is currently used? For example, on android v4.4 you can swipe between dalvik and art and i want to find out this information in runtime.

10x.

user1733773
  • 360
  • 2
  • 14

1 Answers1

3

System.getProperty("java.vm.version") - If ART is used by the system, the returned value will be either "2.0.0" or higher, meaning major versions lower than 2 will be Dalvik. This piece of insight comes from Addressing Garbage Collection (GC) Issues section of best practices for Verifying App Behavior on the Android Runtime.

Code examples

// catch only version 2 and not higher
// false for Dalvik, true for current ART, false for any new runtimes
boolean isArt = System.getProperty("java.vm.version").startsWith("2.");

// catch version 2 and above
// false for Dalvik, true for current ART, true for any new runtimes
boolean isArt = false;
try {
    isArt = Integer.parseInt(System.getProperty("java.vm.version")
            .split(".")[0]) >= 2;
} catch (NumberFormatException e) {
    // we suppress the exception and fall back to checking only for current ART
    isArt = System.getProperty("java.vm.version").startsWith("2.");
}
Valter Jansons
  • 3,904
  • 1
  • 22
  • 25
  • As the docs say the value is always going to be present, you can just use [`.startsWith("2.")`](http://developer.android.com/reference/java/lang/String.html#startsWith(java.lang.String)) on it to catch "2.x.x". If you want to also catch higher versions, you gotta do at least some rough parsing. – Valter Jansons Nov 20 '14 at 18:17