我正在从 SDK 版本 30 升级到 31,我在 intent-filter 中添加了 android:exported 但我仍然收到此错误:
合并错误:错误:需要为 .当相应组件定义了 Intent 过滤器时,面向 Android 12 及更高版本的应用需要为 android:exported
指定一个明确的值。参见 https://developer.android.com/guide/topics/manifest/activity-element#exported了解详情。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mycompany.webviewapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity android:name="com.mycompany.webviewapp.SplashActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.mycompany.webviewapp.MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.VIEW"></action>
</intent-filter>
</activity>
<service android:name="com.mycompany.webviewapp.FCM.MyFirebaseMessagingService">
</service>
<meta-data android:name="applovin.sdk.key"
android:value="sdk api here"/>
</application>
</manifest>
最佳答案
原因是因为您正在使用的某些依赖库包含没有“android:exported”属性的元素。
你需要这样做:
- 将 gradle 中的版本降低到 30 并同步和构建。
- 转到您的 AndroidManifest.xml 文件并单击“合并 list ”。
- 查找没有“android:exported”属性的项目,例如 Activity、Receiver、Service 等。
- 然后以这种方式将它们添加到您的 AndroidManifest.xml 文件中。
<activity
android:name="SomeActivity"
android:exported="false"
tools:node="merge"
tools:replace="android:exported" />
现在您可以将版本增加到 31。
关于java - 我设置安卓 :exported but I am still getting error: android:exported needs to be explicitly specified for <receiver>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71008027/