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

升级Android Studio Artic Fox后自定义View无法在布局预览渲染求助

可行解决方案

  • 首先检查根目录gradle.properties的配置,AGP 7.0默认开启非传递R类特性,未适配的老项目会出现布局预览无法索引自定义View类的问题,添加如下配置后重新构建即可:
    android.nonTransitiveRClass=false
    
  • 执行全量缓存清理操作:
    1. 关闭Android Studio,手动删除项目根目录下的.idea、.gradle文件夹,以及所有模块下的build文件夹
    2. 重新打开Android Studio,等待索引完成后依次执行Build > Clean Project、Build > Rebuild Project
    3. 重启布局预览页面验证
  • 检查模块级build.gradle的buildFeatures配置,若你使用了ViewBinding或DataBinding,确保已显式开启对应配置:
    android {
        buildFeatures {
            viewBinding true
            // 使用DataBinding时添加下方配置
            dataBinding true
        }
    }
    
  • 若自定义View存放在独立子模块中,检查主模块对该子模块的依赖声明,如果是implementation依赖需要改为api,AGP 7.0强化了依赖隔离,implementation依赖的子模块类不会对外暴露,会导致预览无法识别类。
  • 若项目使用Kotlin和kapt,在gradle.properties中添加kapt.incremental.apt=false关闭kapt增量编译,避免编译生成的类索引异常。

对应错误提示:
Missing Class:
以下类无法找到

com.poetryrocksalot.dummyproject.widget1 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget2 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget3 (Fix Build Path, Edit XML, Create Class)
...

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.09 11:39:03