Android Studio marks R in red with error message "cannot resolve symbol R", but build succeeds

android, android-studio, gradle

Solution

Here is my temporary solution until I find a better one:

Using Everything, find where R.java is created. In my case it was `C:\Program Files (x86)\Android\android-studio\system\compiler\<project-name>.cb969c52\.generated\aapt\<module-name>.6badd9a4\production\com\<project-name>\<module-name>`

In the Project view, click the module and press F4. Ignore the warning.

Click "+ Add Content Root" and select the aforementioned folder. Make sure it's marked in blue (as a source).

After I did this, suddenly all the warnings are gone. The problem is that if you collaborate with other people, the folder name is different on each machine so be careful when synchronizing.

Problem

In every project I've tried to create in Android Studio, all usages of R are marked in red with the error message "cannot resolve symbol R", but the compilation succeeds and the application runs. This is really annoying, as it blocks auto-completion and shows huge red waved lines all over my code. I'm running Android Studio 1.7.0 and creating the project with default settings. A screenshot is attached: This is my `build.gradle`: ``` buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.4' } } apply plugin: 'android' dependencies { compile files('libs/android-support-v4.jar') } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 16 } } ``` This is how the Project Structure looks like: Any idea how to fix this?

Original source

Related problems