Cannot resolve R.java, duplicate class

I am just starting to use Android Studio for a week and it works great for me, but when I started Android Studio today, I get the error message: "error: duplicate class: mypackage.R". I saw this error before when I used Eclipse, so I tried several times to rebuild the project and restart Android Studio, this did not help.

After reading some Stackoverflow questions, I tried to uninstall R.java and restore again, now I am not getting any recovery errors. The only problem is that Android Studio cannot resolve R, so every line using R gets an error (collecting and starting the project).

I also tried deleting all R.class files, but that does not help either. I checked if any android.R class imports, but they all do not, they just import 'mypackage.R'. I even deleted all my files and checked an older version of my project, but I still have the same problem.

Edit:

If I do not delete R.java, the compiler does not give any error. Just when I try to build, I get a lot of errors, such as: "error: cannot find the symbol variable button_login". If I search for the R.java file for 'button_login', I just find it. I did this with a few mistakes.

Edit2:

When I deleted all the libraries that are now building the project. But the problem is that I need these libraries (HTTPComponents). I added them from maven (File -> Project Structure -> Libaries -> + -sign ') and added them to my .graddle settings:

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 } } 

When I run gradlew.bat --stacktrace --info assemble , I get errors that Gradle cannot find libraries from the maven repository. I checked the repository, but they are available. http://search.maven.org/#browse%7C1628757896

+2
android android-studio r.java-file android-resources
Jun 14 '13 at 8:15
source share
7 answers

Unfortunately, I also encounter this, sometimes often, most often it happens when I make the computer sleep and turn on again while Eclipse is on. Sometimes recompilation and verification of the project.

I found this solution online somewhere, lost the link and do not apply for loans for this:

  • Turn off auto-build and clean up the project, then
  • Right click on your project -> Properties -> Java Build Path -> Source -> Add Folder -> Add Gene and src
  • Then compile

If this does not work, try deleting the gen folder and doing this process

Tell me.

+3
Jun 14 '13 at 8:32
source share

Delete the Build folder generated by Android Studio automatically!

+2
Jun 14 '13 at 10:53 on
source share

The problem is simple. Do you have a new studio? Thus, you simply add SDK support for those versions of Android in which you want to compile the project. Android Studio cannot generate R file. Run the SDK manager, install the entire missing version of the SDK and the rebuld project.

Another problem might be using a 64-bit OS. You have installed the 32-bit lib library because aapt cannot work with 64-bit libraries.

  • in ubuntu install ia32-libs
  • Fedora described here
  • in other sections find libs in google (just google: ia32-libs for "mydistr"), I can not describe them all;)

PS sorry for my english;)

0
Nov 20 '13 at 9:59
source share

Delete all class files in your_package_name(androisTest) folder only save ApplicationTest file.

0
Jan 11 '16 at 11:03
source share

If you use any library from which you get this error, simply delete the build folder in your application source and rebuild the project. I used the OpenCV library, for which I am getting this error, and which was resolved by deleting the build folder and restoring the project.

0
Aug 06 '16 at 16:26
source share
  • Delete all the generated code inside the gen folder.
  • Uncheck the box Project-> Build Automatically in eclipse.
  • compile the Android source again.
  • The error will be deleted, it will work for me.
0
Aug 25 '16 at 4:48
source share

This still happens sometimes in Android Studio, but it takes care of a simple Build / Clean project, followed by a Build / Rebuild project.

0
Feb 26 '17 at 11:54 on
source share



All Articles