I am making a simple note taking app in Kotlin Compose and I am trying to add a font from a font file (.otf) but its saying R doesn't exist. Ive tried to import from my package, dev.bluemethyst.apps.notix.R
and it doesn't exist there either.
I have tried invalidating gradle caches, rebuilding gradle, cleaning gradle, recreating the folder and redownloading the fonts. Nothing seems to work, please help me :P
package dev.bluemethyst.apps.notix
import dev.bluemethyst.apps.notix.R
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
val letteraMonoLLFont = FontFamily(
Font(R.font.lettera_mono_ll_regular, FontWeight.Normal),
Font(R.font.lettera_mono_ll_condlight_regular, FontWeight.Bold)
)
You cannot access R
because you are in the commonMain
. To access it, you must be in the androidMain
, as commonMain
does not support platform-specific dependencies.
To resolve this, create an interface
or an expect class
in commonMain
and implement it in both androidMain
and iosMain
. In the androidMain
implementation, you can then access R
.