Cannot resolve 'Offset' reference when compiling with Figma Relay UI components

I keep getting a build error in Android Studio when trying to compile my project:

Cannot resolve reference: ‘Offset’

This issue occurs in the generated code from Figma’s Relay plugin for UI components. Android Studio wants me to import androidx.compose.ui.geometry.offset but since this code gets regenerated every time I build, the import gets lost.

I already added all the required dependencies to both my libs.version.toml and build.gradle files but the error persists. I tried cleaning the project, invalidating caches, and updating to the newest versions of SDK, gradle, and kotlin but nothing works.

Here’s my configuration:

plugins {
    alias(libs.plugins.android.app)
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.firebase.services)
    alias(libs.plugins.compose.compiler)
    alias(libs.plugins.figma.relay)
}

android {
    namespace = "com.example.myapp.birdie"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.example.myapp.birdie"
        minSdk = 24
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.1"
    }
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    implementation(libs.firebase.auth)
    implementation(libs.androidx.credentials)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    implementation(libs.compose.ui)
    implementation(libs.compose.foundation)
    implementation(libs.compose.material)
}

And the generated Relay code that’s causing problems:

package com.example.myapp.birdie.welcomescreen

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import com.google.relay.compose.RelayContainer
import com.google.relay.compose.RelayText

@Composable
fun WelcomeScreen(modifier: Modifier = Modifier) {
    MainContainer(modifier = modifier) {
        HeaderText(
            modifier = Modifier.boxAlign(
                alignment = Alignment.TopStart,
                offset = DpOffset(
                    x = 50.0.dp,
                    y = 100.0.dp
                )
            )
        )
        ActionButton(
            modifier = Modifier.boxAlign(
                alignment = Alignment.TopCenter,
                offset = DpOffset(
                    x = 0.0.dp,
                    y = 400.0.dp
                )
            )
        )
    }
}

@Composable
fun MainContainer(
    modifier: Modifier = Modifier,
    content: @Composable RelayContainerScope.() -> Unit
) {
    RelayContainer(
        content = content,
        modifier = modifier.background(Color.Transparent).drawWithContent(
            onDraw = {
                drawRect(
                    brush = Brush.linearGradient(
                        start = Offset.Zero,
                        end = Offset.Infinite
                    )
                )
                drawContent()
            }
        ).fillMaxWidth(1.0f).fillMaxHeight(1.0f)
    )
}

looks like a version mismatch. your compose compiler extension is on 1.5.1 but relay’s probably expecting newer apis. try bumping it to match your compose bom version - i had the same weird issue until i synced everything up.

This build system complexity is exactly why I stopped fighting these manual configuration battles. Had the same nightmare with Figma Relay generated code getting wiped on every build.

The real issue? You’re dealing with two systems that don’t play nice together. Figma generates code that assumes certain imports, but your build process can’t guarantee they’ll stick around.

I solved this by setting up automation that handles the entire design-to-code pipeline. Instead of fighting Relay’s import issues, I built a flow that pulls from Figma API, processes components, fixes import statements automatically, and rebuilds the project.

The automation runs whenever someone updates the Figma designs. It catches import conflicts before they hit the build system and handles component generation way more reliably than the native Relay plugin.

No more manual fixes to generated code. No more lost imports. Just working builds every time.

You can set this up pretty easily: https://latenode.com

Yeah, this Relay import mess sucks. I’ve dealt with similar generated code nightmares.

Relay generates code expecting imports to exist, but Android Studio’s build system treats generated code as read-only for import resolution. You get stuck in a loop where fixes get wiped every regeneration.

I stopped fighting Relay configs and dependency versions - automated the whole thing instead. Built a workflow that watches my Figma files, pulls designs through API, processes component code, and fixes import conflicts before they hit the build system.

The automation handles version compatibility between Relay and Compose too, so no more geometry import mismatches. Design team updates components in Figma, everything rebuilds cleanly without me touching anything.

Way better than configuring Relay’s import settings or managing BOM versions manually. Build process actually works predictably now instead of constant troubleshooting.

Had this exact problem when migrating to Relay components. Relay generates code that references Offset without importing it properly, and since it keeps regenerating, manually adding imports doesn’t work.

First, check your Relay plugin version in gradle files. Make sure it’s compatible with your Compose setup. I had to downgrade my Relay plugin to match my Compose BOM version.

Also check that libs.versions.toml explicitly includes the geometry library. The BOM doesn’t always pull in all the geometry dependencies Relay needs. Add androidx-compose-ui-geometry = { group = "androidx.compose.ui", name = "ui-geometry", version.ref = "compose" } to your version catalog and dependencies.

Lastly, clear the Relay cache specifically - not just the project cache. Find .relay folders in your project directory, delete them, then rebuild.

Hit this exact same issue with Figma Relay last month. You’re importing DpOffset but using Offset in the drawWithContent block. These are different types - DpOffset is for positioning, Offset is for geometry operations. Your generated code mixes both, hence the compilation error.

Fix: add androidx.compose.ui.geometry.Offset to your Relay config so it auto-imports in generated files. In your build.gradle:

relay {
    autoImports = [
        "androidx.compose.ui.geometry.Offset"
    ]
}

Or you can modify the Figma component to use DpOffset(0.dp, 0.dp) instead of Offset.Zero if that works for your design. I prefer the first approach since you don’t have to touch the Figma file.

The problem is Relay’s drawWithContent block uses raw Offset types for geometry operations, but you’ve only imported DpOffset. These aren’t interchangeable.

I hit this same issue with custom draw operations in Relay components. Here’s what fixed it for me - modify your Relay config to handle geometry imports automatically. In your module’s build.gradle, add this relay block:

relay {
    imports = [
        "androidx.compose.ui.geometry.Offset",
        "androidx.compose.ui.geometry.*"
    ]
}

Or you can add androidx.compose.ui:ui-geometry as an explicit dependency instead of relying on the BOM. Sometimes transitive dependency resolution breaks with generated code.

After making these changes, delete your entire build directory before rebuilding. Relay’s stubborn about cached generated code.