Skip to content

Instantly share code, notes, and snippets.

@derFunk
Created June 18, 2014 10:24
Show Gist options
  • Save derFunk/2f676b17eb5a26b89ba7 to your computer and use it in GitHub Desktop.
Save derFunk/2f676b17eb5a26b89ba7 to your computer and use it in GitHub Desktop.

Revisions

  1. derFunk created this gist Jun 18, 2014.
    31 changes: 31 additions & 0 deletions ReliablyDetectArt.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    /**
    * Checks if the device is using the (still experimental Android Runtime (ART))
    * @return Returns true if ART is used on the device.
    */
    public static boolean isART()
    {
    if (Build.VERSION.SDK_INT < 19) // Before KITKAT, as ART is only available since 4.4.x
    return false ;

    try{
    String bootClassPath = System.getProperty("java.boot.class.path", "");

    if (bootClassPath.contains("core-libart.jar")){
    Log.d(TAG, "java.boot.class.path contains core-libart.jar - Using ART :(");
    return true;
    }
    else {
    Log.d(TAG, "java.boot.class.path does not contain core-libart.jar - Not using ART :)");
    return false;
    }
    }
    catch(Exception e){
    android.util.Log.d(TAG, e.toString());
    }

    // If not found - return false because if when
    // returning true, and there is no ART, it would
    // be worse to display a popup "you cannot play, you're using ART",
    // instead of crashing the app instantly
    return false;
    }