You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Layout Inspector在Jetpack Compose中无法使用:无法识别ui构件版本求助

解决Layout Inspector无法识别Jetpack Compose版本的问题

错误提示:

Compose inspection unavailable. Could not determine the version of the androidx.compose.ui:ui artifact. Was the version file excluded?

以下是具体解决步骤:

  • 检查Compose依赖配置
    确保模块级build.gradle(或build.gradle.kts)里正确引入androidx.compose.ui:ui及配套工具依赖,版本要明确。示例配置:

    dependencies {
        implementation "androidx.compose.ui:ui:1.6.0"
        implementation "androidx.compose.material3:material3:1.2.0"
        // Layout Inspector依赖的调试工具
        debugImplementation "androidx.compose.ui:ui-tooling:1.6.0"
        debugImplementation "androidx.compose.ui:ui-test-manifest:1.6.0"
    }
    

    注意ui-tooling是Layout Inspector正常工作的必要项,必须在debug编译环境中添加。

  • 移除不必要的依赖排除规则
    检查项目配置里有没有通过exclude移除androidx.compose.ui:ui的代码,比如:

    configurations.all {
        exclude group: 'androidx.compose.ui', module: 'ui'
    }
    

    如果有这类配置,直接删除,确保Compose版本元数据能被正常识别。

  • 清理重构项目并重启IDE

    1. 点击Android Studio顶部菜单栏的Build -> Clean Project
    2. 再点击Build -> Rebuild Project
    3. 重启Android Studio,重新连接设备后打开Layout Inspector
  • 匹配Android Studio与Compose版本
    Compose和Android Studio版本需要兼容,比如:

    • Compose 1.6.x 建议搭配 Android Studio Hedgehog (2023.1.1) 及以上版本
      要是版本不匹配,要么升级Android Studio,要么调整Compose依赖版本到适配当前IDE的范围。
  • 确认应用以Debug变体运行
    确保连接的设备/模拟器开启了调试模式,并且安装运行的是应用的debug变体——release变体通常会移除调试工具,导致Layout Inspector无法工作。

内容的提问来源于stack exchange,提问作者Zixuan Zhu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 22:57:32