title: Cannot resolve R.java, duplicate class
body: <p>I just start using Android Studio for a week and it works great for me, but when I started Android Studio today I get the error: 'error: duplicate class: mypackage.R'. I saw this error before when I used Eclipse so I tried to rebuild the project a few times and restarting Android Studio, this didn't help. </p>
  
  <p>After reading some Stackoverflow questions I tried to deleted R.java and rebuild again, now I don't get any error while rebuilding. The only problem is that Android Studio cannot resolve R, so every line which uses R gets an error (project builds and run). </p>
  
  <p>I also tried to delete all the R.class files but this doesn't help either. I checked if some class imports android.R, but they all don't, they just import 'mypackage.R'. I even deleted all my files and checked out a older version of my project but I still have the same problem.</p>
  
  <p>Edit:</p>
  
  <p>If I don't delete R.java the compiler doesn't give any error. Just when I try to build I get a lot of errors like: 'error: cannot find symbol variable button_login'. If I search the R.java file for 'button_login' I just find it. I did this with multiple errors.</p>
  
  <p>Edit2: </p>
  
  <p>When I deleted all the libaries the project now builds. But the problem is that I need those libaries (HTTPComponents). I added them from maven (File --> Project Structure --> Libaries --> +-sign') and added them to my settings.graddle:</p>
  
  <pre><code>buildscript {
      repositories {
          maven { url 'http://repo1.maven.org/maven2' }
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:0.4'
      }
  }
  apply plugin: 'android'
  
  dependencies {
      compile files('libs/android-support-v4.jar')
      compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.2.5'
      compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.2.5'
  
      //compile 'org.apache.httpcomponents-httpclient:4.2.5' doesn't work either
      //compile 'org.apache.httpcomponents-httpmime:4.2.5' doesn't work either
  }
  
  android {
      compileSdkVersion 17
      buildToolsVersion "17.0.0"
  
      defaultConfig {
          minSdkVersion 15
          targetSdkVersion 16
      }
  }
  </code></pre>
  
  <p>When I run <code>gradlew.bat --stacktrace --info assemble</code> I get errors that Gradle is unable to find the libaries from the maven repository. I checked the repository but they are available. <a href="http://search.maven.org/#browse%7C1628757896" rel="nofollow">http://search.maven.org/#browse%7C1628757896</a></p>