Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA - Can't build anything, always get "package R does not exist"

I'm trying to use IntelliJ IDEA to work on an Android app with a colleague that swears by it, but I'm unable to build any of the Android projects he sends me because whenever I try a build I get an error saying package R does not exist.

I have been trying out everything I can think of. Examples and other things to note are:

  • Making sure I have a version of the local.properties file pointing to the root of my Android SDKs folder.

  • Fiddling with various settings in the project structure dialog (I won't list them all).

  • The project I'm working on has two library projects with also use the R class and they work fine.

  • The intellisense within the IDE recognises the R class and comes up with the stuff I expect.

Any help would be greatly appreciated. I feel I'm missing something basic.

like image 432
Mick Byrne Avatar asked Oct 02 '12 07:10

Mick Byrne


2 Answers

I am brand new to IntelliJ so I apologize if this doesn't work for you. I was experiencing the same problem and the solution was to add an Android Facet to your project.

(I am on a Mac, so directions here may be slightly off, and there are probably better ways to find this window, if so let me know!)

  1. Right click your project and go down to Open Module Settings (seems F4 also works)
  2. Select Facets in the far left column
  3. Click the + button
  4. Add an Android Facet to your project, and VOILA!
  5. You may need to import your Rs now, which could be a huge pain... so hopefully someone can chime in with an easy way to auto-import

Hope this helps someone!

like image 116
xbakesx Avatar answered Oct 02 '22 12:10

xbakesx


Another possible solution to those listed here is to check that the package name in your AndroidManifest.xml matches that of your actual package:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.yourpackagename" >

My package was building fine until I refactored the package name, everything refactored except for the package name in manifest file (see above) which caused the error "Package R does not exist".

like image 43
Bulwinkel Avatar answered Oct 02 '22 14:10

Bulwinkel