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

React Native真机构建失败:android:attr/endY、ttcIndex缺失求助

问题分析与解决方法

问题根源

报错里的android:attr/endY、android:attr/ttcIndex是Android API Level 28(Android 9)新增的资源属性,你使用的react-native-file-opener和react-native-fetch-blob两个第三方库的Android模块配置未适配高版本SDK,导致构建Release包时资源合并失败。

解决步骤

1. 优先升级第三方库

检查并升级这两个库到最新版本,新版本通常已修复SDK兼容问题:

  • 执行命令更新:
npm update react-native-file-opener react-native-fetch-blob
# 或使用yarn
yarn upgrade react-native-file-opener react-native-fetch-blob

注:react-native-fetch-blob已停止维护,可替换为活跃维护的分支rn-fetch-blob

2. 手动修改库的Android配置(无法升级时使用)

找到项目中以下文件:

  • node_modules/react-native-file-opener/android/build.gradle
  • node_modules/react-native-fetch-blob/android/build.gradle

修改文件中的compileSdkVersion和targetSdkVersion为你项目使用的版本(比如33,需和项目根目录android/build.gradle中的版本一致)。

3. 统一所有子模块的SDK版本(推荐,避免重复修改)

在项目根目录的android/build.gradle中,给allprojects下的subprojects添加配置:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            android {
                compileSdkVersion 33 // 替换为你项目的compileSdkVersion
                targetSdkVersion 33 // 替换为你项目的targetSdkVersion
            }
        }
    }
}

此配置会强制所有第三方库的Android模块使用和主项目一致的SDK版本,避免版本冲突。

4. 清理缓存后重新构建

执行以下命令清理构建缓存:

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

之后重新运行部署命令:

npx react-native run-android --deviceId <你的设备ID>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 14:45:14