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
- 点击Android Studio顶部菜单栏的
Build->Clean Project - 再点击
Build->Rebuild Project - 重启Android Studio,重新连接设备后打开Layout Inspector
- 点击Android Studio顶部菜单栏的
匹配Android Studio与Compose版本
Compose和Android Studio版本需要兼容,比如:- Compose 1.6.x 建议搭配 Android Studio Hedgehog (2023.1.1) 及以上版本
要是版本不匹配,要么升级Android Studio,要么调整Compose依赖版本到适配当前IDE的范围。
- Compose 1.6.x 建议搭配 Android Studio Hedgehog (2023.1.1) 及以上版本
确认应用以Debug变体运行
确保连接的设备/模拟器开启了调试模式,并且安装运行的是应用的debug变体——release变体通常会移除调试工具,导致Layout Inspector无法工作。
内容的提问来源于stack exchange,提问作者Zixuan Zhu
相关产品推荐
相关产品推荐

