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

React Native添加Facebook依赖后出现android:exported构建错误

React Native 集成Facebook认证时Android 12+构建错误解决办法

我给React Native应用加Facebook认证时,按步骤在Gradle Scripts | build.gradle (Module: app)的dependencies里加了implementation 'com.facebook.android:facebook-android-sdk:latest.release',结果构建时报错:

Error: android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined.

我明明已经在AndroidManifest.xml里给MainActivity设置了android:exported="true",为啥还报错?


问题根源

Facebook SDK会自动往你的AndroidManifest.xml中注入几个带intent-filter的组件(比如登录回调用的Activity),这些组件没有显式设置android:exported,而你的应用目标是Android 12+,系统强制要求所有带intent-filter的组件必须明确该属性,因此触发了构建错误。

解决步骤

  1. 打开AndroidManifest.xml,在<application>标签内添加以下代码,显式声明Facebook相关组件并补上android:exported属性:
<!-- Facebook 回调Activity -->
<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name"
    android:exported="true" />

<!-- Facebook 登录自定义Tab Activity -->
<activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/fb_login_protocol_scheme" />
    </intent-filter>
</activity>

注意:@string/fb_login_protocol_scheme需要在res/values/strings.xml中定义,格式为fb加上你的Facebook App ID,示例:

<string name="fb_login_protocol_scheme">fb123456789012345</string>
  1. 若使用的是较新版本的Facebook SDK,建议检查是否有其他被注入的组件,只要是带有intent-filter的组件,都需要补充android:exported属性。

  2. 重新同步Gradle并构建项目,错误即可消除。

额外建议

不要用latest.release指定SDK版本,容易引发兼容性问题,直接锁定一个稳定版本(比如17.0.0),修改build.gradle中的依赖:

implementation 'com.facebook.android:facebook-android-sdk:17.0.0'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 10:10:23