Home > Blockchain >  Android Studio cannot find R (Resources) after Java to Kotlin conversion
Android Studio cannot find R (Resources) after Java to Kotlin conversion

Time:06-21

Problem

Every time I paste a Java code from somewhere, I select yest to the Android Studio prompt asking to convert it from Java to Kotlin. But after that happens, I seem to have all my previously working R based resources like R.drawable and R.string as unresolved.

enter image description here

What have I tried so far ?

Every time this happens, I copy the converted code and then Ctrl Z up to a point where everything is back to being resolved and then paste the converted Kotlin code, which seems to be okay as it doesn't create any resource resolve issues.

I am running Android Studio Chipmunk 2021.2.1 Patch 1

CodePudding user response:

When the conversion is happening, Android Studio will auto import android.R package. Which will cause discrepancies. Once you are done getting the code converted, just delete the auto import which should ideally be at the top of the file.

import android.R

This anomalous auto import is actually seen through history. It persisted even in Eclipse.

  • Related