Android Studio 3.1.3 - Unresolved reference: R - K

2020-06-30 09:09发布

I am new to kotlin, i have converted some code from java but it seems like there's something wrong, The R in findViewById( is highlighted in red and it shows this message : "Unresolved reference: R".. I've been looking for a solution but i seem not to figure it out, So what should i do? Here's a screenshot :

enter image description here

2楼-- · 2020-06-30 09:30

This worked for me. How much work it is depends on how big your project is. I started a new project, created the required modules (XML, Kotlin, colors, strings, etc.), then copied the code into the modules in the new project from the modules in the old project. Copying XML saves a lot of time compared to recreating the UI. All in all, it take a little while, but I have spent much more time tring to fix the unresolved reference error without it.

3楼-- · 2020-06-30 09:31

I used and had the same issue. Changing to stable Version 3.2.1 solved this problem for me.

4楼-- · 2020-06-30 09:34

Here is the solution, File->Project Structure->Project, select Android Gradle Plugin Version as 3.2.1 from the drop-down. then click apply.

5楼-- · 2020-06-30 09:35


Go to the content_main.xml file and there you need to change the

android:id="@+id/??????"> line of code to whatever id you have given to your file.

Replace question mark ?????? with the related file id name.(IF you dont know the id go to the design tab on the bottom and click on the related Asset.

On the right side below attributes, you can find the ID you have given to it. If it is blank you can freshly name it and Android Studio will write the code.

Then restart Android Studio. Hope this will help. Happy coding.

6楼-- · 2020-06-30 09:35

Downgrading gradle version worked for me.

I changed :

Gradle version from : 4.10.4 to 4.4.1

and Gradle Plugin version from : 3.3.1 to 3.1.3

The star\"
7楼-- · 2020-06-30 09:41

I had the same problem with R reference too. Finally Android Studio 3.3 has been released and using '' the problem has been fixed!

登录 后发表回答