How to check if a library is present during installation? How can I check if the library, which is required by my module, is present while the module is getting installed?

I have used hook_requirements with the libraries_detect function with REQUIREMENT_ERROR severity. This restricts the module from getting installed irrespective of the library is present of not.

Here is my code:



function hook_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'install') {
    if (function_exists("libraries_detect") && !libraries_detect('external-lib-api')) {
      $requirements['library_api'] = array(
        'severity' => REQUIREMENT_ERROR,
        'description' => $t(
          'The required Libarary is not installed.'
        )
      );
    }
  }

  return $requirements;
}



Am I doing something wrong in this? Is there any other way of doing it?
this is one of the working example from my module. I hope this helps you

function sfs_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'install' &amp;&amp; function_exists('libraries_get_path')) {
     $plupload_path = libraries_get_path('plupload');
     $chosen_path = libraries_get_path('chosen');
     if (!$plupload_path) {
       $requirements['plupload'] = array(
         'severity' =&gt; REQUIREMENT_ERROR,
         'description' =&gt; $t('Secure File Share module requires !plupload, which is missing. Download and extract the entire contents of the archive into the %path directory on your server.',  array('!plupload' =&gt; l($t('Plupload Library'), 'https://github.com/moxiecode/plupload/archive/v1.5.8.zip'), '%path' =&gt; 'sites/all/libraries/plupload')), 
       );
     }
     if (!$chosen_path) {
        $requirements['chosen_js'] = array(
          'severity' =&gt; REQUIREMENT_ERROR,
          'description' =&gt; $t('Secure File Share module requires !chosen, which is missing. Download and extract the entire contents of the archive into the %path directory on your server.', array('!chosen' =&gt; l($t('Chosen Library'), 'https://github.com/harvesthq/chosen/releases/download/v1.3.0/chosen_v1.3.0.zip'), '%path' =&gt; 'sites/all/libraries/chosen')),
        );
      }
  }
  return $requirements;
}




Karthik