解决 La fusion du manifeste a échoué : android:exported doit être explicitement spécifié pour <activity>

Annuaire d'articles

scène d'erreur

Lors de l'exécution d'un ancien projet, les erreurs suivantes sont signalées lors de la compilation

Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : android:exported needs to be explicitly specified for <activity>. 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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Solution

Selon l'invite d'erreur, lorsque la targetSdkVersion est supérieure ou égale à SDK 21 (c'est-à-dire Android 12), si certaines activités sont configurées avec Intent-filter, l'attribut exporté doit également être configuré, sinon la compilation échouera.

Nous avons donc 2 solutions

  1. Réduisez targetSdkVersion à 30.
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        //targetSdkVersion 31
        targetSdkVersion 30
    }
  1. Ajouter l'activité avec le filtre d'intention configuré dans le manifesteandroid:exported属性
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:launchMode="standard"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Je suppose que tu aimes

Origine blog.csdn.net/adojayfan/article/details/123243312
conseillé
Classement