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

React Native添加启动屏后出现Class not found Relative Layout错误求助

解决React Native启动屏Class not found Relative Layout错误
  • 修正launch_screen.xml中的布局标签
    打开android/app/src/main/res/layout/launch_screen.xml,将根布局的RelativeLayout替换为AndroidX兼容的版本:

    <!-- 替换前 -->
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- 内容 -->
    </RelativeLayout>
    
    <!-- 替换后 -->
    <androidx.appcompat.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- 内容 -->
    </androidx.appcompat.widget.RelativeLayout>
    

    也可以直接使用Android官方推荐的ConstraintLayout替代:

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- 内容 -->
    </androidx.constraintlayout.widget.ConstraintLayout>
    
  • 确认AndroidX配置正确
    检查android/gradle.properties文件,确保包含以下配置:

    android.useAndroidX=true
    android.enableJetifier=true
    
  • 清理缓存并重新构建
    执行命令清理项目缓存,避免缓存导致的类引用异常:

    cd android
    ./gradlew clean
    cd ..
    npx react-native run-android
    

原因说明

这个错误的核心是AndroidX迁移后,旧support库中的RelativeLayout类已被移除,替换为AndroidX命名空间下的对应类。如果启动屏布局仍使用旧的RelativeLayout标签,系统会找不到对应的类文件,从而抛出Class not found异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 19:57:15