In every instance in all of my classes where I reference R.id.something, the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine. It is annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from Eclipse. I am using what I believe to be the most recent version of Android Studio and the project was created with Android Studio and worked without any "cannot resolve R" problems. I would like to know what causes this if anyone knows.


当前回答

在我做“建立->清洁项目”和“同步项目与gradle”。它们都不是解。我从3.3.0 => 3.2.1(恢复为项目初始状态)下构建gradle版本,它解决了我的问题。

其他回答

我不得不在android studio中导入我的R包。例如:import com.example。<包名称>。R

Build ->清理项目或重建项目 或 File -> Invalidate cache / Restart…->失效并重启

我也有这个问题。简单的“gradlew clean”和“gradlew build”就成功了。


点击Build->Clean Project,将执行gradle Clean

这个符号看起来很好用。

android:id="@+id/viewID"

Android Studio的设计面板似乎不太好用。

我已经做了其他答案中提到的所有步骤,但它仍然没有得到解决。我正在使用android工作室花栗鼠,最后我能够通过删除来解决这个问题

maven { url "https://jitpack.io" }

从设置。gradle我在回答这个问题,我认为这样做可能会帮助到一些人