Search code examples
androidandroid-studioandroid-gradle-pluginandroid-jetpack-composelayout-inspector

Compose inspection unavailable. Could not determine the version of the androidx.compose.ui:ui artifact. Try a different version of compose


I'm getting the error message above when trying to use Layout inspector on my Project when I'm using Android Studio Giraffe | 2022.3.1 Canary 6.

I also tried it with Android Studio Electric Eel | 2022.1.1 Patch 1. There I only get the error message: Compose inspection is not available.

For version Control I'm using chris banes's BOM

composeOptions {
        kotlinCompilerExtensionVersion '1.4.0'
    }

dependencies{
androidx.compose = 2023.02.00-alpha02
..
implementation platform("dev.chrisbanes.compose:compose-bom:${androidx.compose}")
    androidTestImplementation platform("dev.chrisbanes.compose:compose-bom:${androidx.compose}")
    implementation "androidx.compose.ui:ui"
    implementation "androidx.compose.ui:ui-util"
    implementation "androidx.compose.material:material"
    implementation "androidx.compose.material:material-icons-extended"
    implementation "androidx.compose.ui:ui-tooling"
    debugImplementation "androidx.compose.ui:ui-tooling"
    implementation "androidx.compose.ui:ui-tooling-preview"

I also tried to use own verrsions without using the BOM but that gave me the same issue. Invalidating Cache and Rebuilding Project also didn't work.

Has anybody an idea how I can fix this and start using my Layout inspector again?


Solution

  • Fix

    As mentioned previously, the fix is to bump compose-ui to 1.4.0-beta02:

    implementation("androidx.compose.ui:ui:1.4.0-beta02")
    

    (or via Version Catalogs:)

    name-of-library = "androidx.compose.ui:ui:1.4.0-beta02"
    # Or
    name-of-library = { module = "androidx.compose.ui:ui", version = "1.4.0-beta02" }
    

    Or to use 2023.02.00-beta03 of the alpha Compose BoM:

    implementation(platform("dev.chrisbanes.compose:compose-bom:2023.02.00-beta03"))
    

    (or via Version Catalogs:)

    name-of-bom = "dev.chrisbanes.compose:compose-bom:2023.02.00-beta03"
    # Or
    name-of-bom = { module = "dev.chrisbanes.compose:compose-bom", version = "2023.02.00-beta03" }
    

    Rationale

    This is because the androidx.compose.ui_ui.version file (in the META-INF directory of a built APK) that the Layout Inspector expects has an invalid version:

    task ':compose:ui:ui:writeVersionFile' property 'version'
    

    (Curiously enough, this also happens for some other dependency versions:)

    (androidx.browser_browser.version)

    task ':browser:browser:writeVersionFile' property 'version'
    

    Some quick googling in Google's IssueTracker led to an issue, which documents the bug affecting versions 1.4.0-alpha05, 1.4.0-alpha06 and 1.4.0-beta01.

    A fix was then submitted to resolve the version issue, and has since been applied to 1.4.0-beta02 (released on 22 Feb).

    Additional info

    This bug appears to have been caused by a prior change to convert the properties in the VersionFileWriterTask file (used to write the version file) to use Gradle's lazily configured properties:

    @get:Input
    lateinit var version: String // Before
    abstract val version: Property<String> // After (note the use of Property)
    

    However, as version is now wrapped around Gradle's Property interface, it will then require additional code to retrieve its value, in this case with a simple get() call (as shown in the most recent commit):

    writer.println(version) // Before
    writer.println(version.get()) // After