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

React Native Android构建时@react-native-masked-view的package属性被移除问题

解决React Native Android构建时@react-native-masked-view的AndroidManifest.xml package属性被移除问题

问题描述

每次执行构建、切换构建变体或Gradle同步操作时,@react-native-masked-view包的AndroidManifest.xml文件中的package属性会被自动移除,导致构建报错「No package name found」。手动将仓库原始的package="org.reactnative.maskedview"属性粘贴回文件后可正常构建,但下次操作时问题会重复出现。

构建后异常文件内容:

<manifest  xmlns:android="http://schemas.android.com/apk/res/android"></manifest>

仓库原始正确内容:

<manifest package="org.reactnative.maskedview" xmlns:android="http://schemas.android.com/apk/res/android"></manifest>

解决方案

  • 检查版本兼容性
    确认@react-native-masked-view版本与当前React Native版本适配,版本不匹配可能导致Gradle处理清单文件时出现异常。例如React Native 0.60+需使用对应适配的包版本。

  • 阻止Gradle修改清单文件
    在项目根目录的android/build.gradle中添加配置,锁定该包的清单文件路径:

    subprojects {
        afterEvaluate { project ->
            if (project.name.contains('react-native-masked-view')) {
                android {
                    sourceSets {
                        main {
                            manifest.srcFile 'src/main/AndroidManifest.xml'
                        }
                    }
                }
            }
        }
    }
    
  • 强制保留package属性
    在app模块的AndroidManifest.xml中声明tools命名空间,并通过tools:replace强制保留目标包的package属性:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools">
        <!-- 其他配置 -->
        <uses-library android:name="org.reactnative.maskedview" tools:replace="package"/>
    </manifest>
    
  • 清理缓存并重装依赖
    执行以下命令彻底清理缓存并重新安装依赖:

    ./gradlew clean
    rm -rf node_modules
    rm package-lock.json yarn.lock
    npm install
    ./gradlew assembleDebug
    
  • 设置文件只读锁定
    将@react-native-masked-view的AndroidManifest.xml设置为只读,阻止Gradle修改:

    • Linux/macOS:
      chmod 444 node_modules/@react-native-masked-view/masked-view/android/src/main/AndroidManifest.xml
      
    • Windows:右键该文件 → 属性 → 勾选「只读」。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 12:46:23