简体   繁体   中英

Trying to upgrade SDK version but error "Apps targeting Android 12 and higher are required to specify an explicit value"

I'm trying to upgrade my SDK Version from 30 to 31, and add some android:export="true" to my manifest but still got error Error: 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.

Here for my manifest

    <application
        android:name=".app.MyApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/NoActionBar">
        <activity android:name=".ui.SplashScreen"
            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=".MainActivity"
            android:screenOrientation="portrait"
            android:exported="false"
            android:theme="@style/NoActionBar"
            android:windowSoftInputMode="stateHidden"/>

        <service
            android:name=".firebase.FcmServices"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

What's wrong with my codes? Is there something missing?

Actually it works fine, and the docs show it too:

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdService

https://firebase.google.com/docs/cloud-messaging/android/client#manifest

Weird thing is that when I tested it initially, it didn't work. Only later. No idea how it's possible. Probably some bug on Android.

Anyway, this is from the docs:


<service
    android:name=".java.MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

<!-- FirebaseInstanceIdService performs security checks at runtime,
      no need for explicit permissions despite exported="true"             -->
 <service android:name=".MyFirebaseInstanceIdService" android:exported="true">
     <intent-filter>
         <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
     </intent-filter>
 </service>


It is very simple, You need to set android:exported="true" in the <service> tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Apps targeting Android 12 and higher are required to specify an explicit value for 'android:exported' but I have such value android:exported added but still getting error Apps targeting Android 12 and higher are required to specify an explicit value for android:exported android - Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` Apps targeting Android 12 and higher are required to specify an explicit value for 'android:exported' Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` - andriod studio Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` how to solve = Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported`? Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value .NET MAUI Firebase Messaging: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when intent filter React-native: "Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding.."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM