2

Have an already existing java project. Trying to add new kotlin files to it. AndroidStudio 3.1 complains that R is an "Unresolved reference".

I can manually import R and it builds without error. But why is R not automatically imported as always?

Edit- clean&build or restarting AS didnot help.

anoo_radha
  • 770
  • 1
  • 13
  • 30

3 Answers3

1

See imports inside kotlin file. Package names might be from your old project, that won't allow you to use R. Delete them, and reimport

Jack
  • 1,395
  • 2
  • 10
  • 20
1

I found a solution. Just import your main package R in your kotlin file where you got this error.

Like:

import com.example.activities.R
4b0
  • 20,627
  • 30
  • 92
  • 137
vinod
  • 1,056
  • 15
  • 18
0

In AS Preferences, under General -> Auto Import, i enabled the following. enter image description here

This imports R automatically now.

anoo_radha
  • 770
  • 1
  • 13
  • 30