title: Gradle failed to sync with 'unable to find optional library'
body: <p>I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:</p>
  
  <pre><code>Warning: Unable to find optional library: org.apache.http.legacy
  </code></pre>
  
  <p>My project gradle is:</p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:1.3.0'
      }
  }
  
  allprojects {
      repositories {
          mavenCentral()
      }
  }
  </code></pre>
  
  <p>And my module gradle:</p>
  
  <pre><code>apply plugin: 'android'
  
  android {
      useLibrary  'org.apache.http.legacy'
  
      compileSdkVersion 23
      buildToolsVersion '23.0.2'
      defaultConfig {
          minSdkVersion 16
          targetSdkVersion 23
      }
      buildTypes {
          release {
          }
      }
      productFlavors {
      }
  }
  
  dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      compile 'com.android.support:support-v4:23.1.1'
      compile 'com.android.support:appcompat-v7:23.1.1'
  }
  </code></pre>
  
  <p><a href="http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client" rel="noreferrer">From the google docs</a>:</p>
  
  <blockquote>
    <p>To continue using the Apache HTTP APIs, you must first declare the
    following compile-time dependency in your build.gradle file:</p>
  
  <pre><code>android {
      useLibrary 'org.apache.http.legacy'
  }
  </code></pre>
  </blockquote>
  
  <p>I tried the suggestions mention in <a href="https://stackoverflow.com/questions/31653002/how-to-use-the-legacy-apache-http-client-on-android-m">this thread</a> but they don't work. Same result with android studio 1.5 and 2 preview.</p>
  
  <p>How can I fix this?</p>
  
  <p><strong>Edit</strong>: Things I've tried so far:</p>
  
  <ol>
  <li><p>Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0. </p></li>
  <li><p>Change the <code>compileSdkVersion</code> and <code>targetSdkVersion</code> to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.  </p></li>
  </ol>