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

React Native Webview应用升级API33到34遇接收器声明错误但无接收器

解决React Native升级targetSdkVersion到34时的「RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED」错误

你遇到的问题是因为第三方依赖库在它们的AndroidManifest中声明了接收器,但没有指定exported属性——虽然你自己的代码里没写任何接收器,但依赖库的清单会被合并到你的应用最终清单里,targetSdk34要求所有接收器必须明确android:exported为true或false。

排查步骤

  1. 生成合并后的完整清单文件,执行命令:
    ./gradlew :app:mergeDebugAndroidManifest
    
  2. 打开路径app/build/intermediates/merged_manifests/debug/AndroidManifest.xml,搜索<receiver>标签,找到所有没有android:exported属性的接收器,这些就是触发错误的根源。

解决方案

方案一:升级依赖库到适配targetSdk34的版本

检查你用到的依赖,优先升级到最新稳定版:

  • @react-native-community/geolocation:这个库已停止维护,建议替换为React Native内置的Geolocation(RN 0.60+已集成,无需额外安装);
  • react-native-webview:升级到v13.0.0及以上版本,新版本已适配Android 14的要求;
  • 其他依赖也尽量升级到支持targetSdk34的版本。

方案二:在自己的清单中覆盖第三方接收器的属性

如果暂时无法升级依赖,可在你的android/app/src/main/AndroidManifest.xml中强制给第三方接收器添加exported属性:

  1. 先在Manifest根标签添加tools命名空间:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="com.yourpackage">
    
  2. 找到合并清单里的目标接收器,添加如下代码(替换为实际的接收器类名):
    <receiver
        android:name="com.example.ThirdPartyReceiver"
        android:exported="false"
        tools:replace="android:exported" />
    
    这里android:exported="false"是因为你的应用不需要外部调用这个接收器,若需外部触发可调整为true。

额外建议

  • 升级React Native到0.71.x的最新补丁版,0.71.4可能存在一些适配Android 14的小问题;
  • 执行./gradlew clean清理构建缓存后再重新编译项目。

原提问中的配置信息

package.json

{
  "name": "myapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/geolocation": "^3.0.5",
    "react": "18.2.0",
    "react-native": "0.71.4",
    "react-native-dotenv": "^3.4.8",
    "react-native-loading-spinner-overlay": "^3.0.1",
    "react-native-webview": "^11.26.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/node": "^18.16.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "^0.73.8",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.1.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 15:23:13