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
  • 812
  • 1
  • 15
  • 34

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,545
  • 2
  • 11
  • 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
  • 21,981
  • 30
  • 95
  • 142
vinod
  • 1,126
  • 13
  • 18
0

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

This imports R automatically now.

anoo_radha
  • 812
  • 1
  • 15
  • 34