patridge
patridge

Reputation: 26565

Xamarin.Android build error: duplicate class R.java

I loaded a long-dormant Xamarin.Android project that I last opened in MonoDevelop, when it was still called Mono for Android. Every time I tried to build the project, debug or release, it fails with "Error: duplicate class" pointing to R.java.

Since R.java is just an auto-generated file for the various project resources, I tried editing a filename and letting Xamarin Studio update the file. This didn't resolve the build error.

Similar searches find issues with improperly named IDs in an axml file, but all the IDs in this project appear to meet Android requirements (and it built fine the last time I worked on it to generate the project's APK).

Upvotes: 1

Views: 1956

Answers (2)

Sundara Prabu
Sundara Prabu

Reputation: 2729

  1. delete all files and folders from your c:\users\\appdata\local\xamarin\
  2. Restart VS - very important
  3. Clean Solution
  4. Build / Rebuild solution

If the above ends up with some other resource errors , close and reopen VS and repeat steps 2,3,4.

Upvotes: 1

patridge
patridge

Reputation: 26565

Deleting the project's bin and obj folders entirely and letting them be rebuilt from scratch resolved the build error just fine.

Since the actual R.java file is buried deep in the obj folder, it may have been possible to be a little less eager with the deletes. There is probably a better solution entirely, but this certainly got the job done.

Upvotes: 5

Related Questions