0

I'm getting R cannot be resolved error. I read R cannot be resolved - Android error. But there android.R file. My project compiles if .java files contain import com.companyname.productname.R statement. If I change my productname in AndroidManifest.xml there's many errors saying package com.companyname.productname does not exist. I tried to remove all import com.companyname.productname.R lines, but then I got package R does not exist errors on lines with R.*. How can I work around this? Thanks.

Update:
So answer is yes, I must import com.companyname.productname.R. I managed to compile project after changing productname in AndroidManifest and find-and-replace all import com.companyname.productname.R statements with new productname.

Community
  • 1
  • 1
M.Y.
  • 1,105
  • 1
  • 11
  • 30

1 Answers1

2

You custom R class is generated based on the package name in your AndroidManifest. So if you change it there, it will be newly generated with the new package name.

Therefore make sure that you import the correct one and remove all old imports.

If you R class is not generated, you should check the for XML errors in your resource files and/or your AndroidManifest. Fix the issues there and your R file should be generated again.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • 1
    It's that last paragraph that typically trips people up. Problems in your XML don't show up in Eclipse as obviously as Java syntax errors. Turn on the error log view in Eclipse (Window->Show View) or use the command line build to see if this is your problem. – Eric Cloninger May 24 '12 at 13:43
  • @EricCloninger true. I prefer the Problems View as the error log might contain old errors which can confuse new users. I didn't mention it as the OP doesn't use eclipse but IDEA. – WarrenFaith May 24 '12 at 14:16