Android AAPT报错:0与layout_constraintEnd_toEndOf属性不兼容
报错根因
这个AAPT报错和缓存、IDE安装、kotlin-parcelize插件没有任何关系,核心问题是布局XML中ConstraintLayout约束属性的赋值非法:layout_constraintEnd_toEndOf这类约束属性仅接受两类合法值:一是其他控件的ID引用,二是枚举值parent(代表约束到父布局),你代码里所有写="0"的约束位置,都是把非法值0传给了属性,AAPT校验类型不匹配直接抛出错误。
修复方法
- 打开对应的
splash_main.xml布局文件,将所有约束属性中填写的0全部替换为parent,修正后的完整布局代码如下:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#eef4fb" tools:context=".SplashActivity"> <TextView android:id="@+id/app_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:elevation="2dp" android:fontFamily="@font/bungee" android:text="@string/app_name" android:textAlignment="center" android:textColor="@color/black" android:textSize="50sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/lottie" /> <com.airbnb.lottie.LottieAnimationView android:id="@+id/lottie" android:layout_width="300dp" android:layout_height="300dp" android:elevation="2dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.1" app:lottie_autoPlay="true"/> </androidx.constraintlayout.widget.ConstraintLayout>
- 保存文件后直接正常构建运行即可,不需要执行清理缓存、重装IDE这类额外操作。
其他说明
- 你提供的
build.gradle配置没有问题,ConstraintLayout依赖版本正常,不需要额外添加所谓的补充配置。 - 你当前引入的Lottie 2.8.0版本发布时间较早,如果后续运行时出现Lottie相关兼容问题,可以升级到更新的稳定版,但该问题和本次AAPT报错无关。
内容的提问来源于stack exchange,提问作者Bedo Habashi
相关产品推荐
相关产品推荐

