title: What's the difference between principles of useLibrary and compile files('') in build.gradle?
body: <p>After Android 6.0 releases,  Support for the <strong>Apache HTTP client</strong> is removed. If our app is using this client and targets <strong>Android 2.3 (API level 9) or higher</strong>, <code>HttpURLConnection</code> class is recommended. It's said that this API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. If we want to continue using the <strong>Apache HTTP API</strong>s, you must first declare the following compile-time dependency in our <code>build.gradl</code>e file:</p>
  
  <pre><code>android {
      useLibrary 'org.apache.http.legacy'
  }
  </code></pre>
  
  <p>The legacy jar is in <strong>Android SDK</strong>, whose path is <code>sdk/platforms/android-23/optional/</code>. So, it is nearly independent. Meanwhile, this apache legacy jar is putted into <code>optional/</code> in Android SDK, so what is <code>optional/</code>? What does that mean?</p>
  
  <p>Also we know, we can put this jar into <code>libs</code> and then declare it in our <code>build.gradle</code> file like this:</p>
  
  <pre><code>dependencies {
      compile files('libs/org.apache.http.legacy.jar')
  }
  </code></pre>
  
  <p>Both methods worked as expected when I tested.</p>
  
  <p>But why?</p>
  
  <p>What's the difference between <code>useLibrary</code> and <code>compile files('')</code> in <code>build.gradle</code>? Only because the legacy jar file is in android SDK so I can declare <code>useLibrary</code> in <code>build.gradle</code>to use it? Could I use other jars in this way? </p>
  
  <p>Could somebody provide some ideas about this?</p>