android:exported 需要为 <activity> 明确指定。需要针对 Android 12 及更高版本的应用指定

android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify

升级到android12后,应用程序无法编译。它显示

"Manifest merger failed with multiple errors, see logs"

合并清单中显示错误:

Merging Errors: 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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. main manifest (this file)

我已经将所有 activity 设置为 android:exported="false"。但是还是显示这个问题。

我的清单文件:

<?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="eu.siacs.conversations">

    <uses-sdk tools:overrideLibrary="net.ypresto.androidtranscoder" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission
        android:name="android.permission.READ_PHONE_STATE"
        android:maxSdkVersion="22" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

    <uses-feature
        android:name="android.hardware.location"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.gps"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.network"
        android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.microphone"
        android:required="false" />

    <application
        android:name=".Application"
        android:allowBackup="false"
        android:allowClearUserData="true"
        android:appCategory="social"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_app_launch"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:networkSecurityConfig="@xml/network_security_configuration"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_app_launch_round"
        android:theme="@style/ConversationsTheme"
        android:usesCleartextTraffic="true"
        android:windowSoftInputMode="adjustPan|adjustResize"
        tools:replace="android:label"
        tools:targetApi="q">
        <activity
            android:name=".ui.search.GroupSearchActivity"
            android:exported="true" />
        <activity
            android:name=".ui.profileUpdating.FavouritesActivity"
            android:exported="true" />
        <activity
            android:name=".ui.profileUpdating.NameActivity"
            android:exported="true" />
        <activity
            android:name=".ui.CompulsoryUpdateActivity"
            android:exported="true" />
        <activity android:name=".ui.payments.doPayment.DoPaymentActivity"
            android:exported="true" />
        <activity android:name=".ui.individualList.IndividualListActivity"
            android:exported="true" />
        <activity android:name=".ui.payments.setPayment.SetPaymentActivity"
            android:exported="true" />
        <activity android:name=".ui.login.otpActivity.OTPActivity"
            android:exported="true" />
        <activity android:name=".ui.login.loginActivity.LoginActivity"
            android:exported="true" />

        <service android:name=".services.XmppConnectionService" android:exported="true" />

        <receiver android:name=".services.EventReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.intent.action.ACTION_SHUTDOWN" />
                <action android:name="android.media.RINGER_MODE_CHANGED" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".ui.ShareLocationActivity"
            android:label="@string/title_activity_share_location"
            android:exported="true"/>
        <activity
            android:name=".ui.SearchActivity"
            android:label="@string/search_messages"
            android:exported="true" />
        <activity
            android:name=".ui.RecordingActivity"
            android:configChanges="orientation|screenSize"
            android:theme="@style/ConversationsTheme.Dialog"
            android:exported="true" />
        <activity
            android:name=".ui.ShowLocationActivity"
            android:label="@string/title_activity_show_location"
            android:exported="true" />
        <activity
            android:name=".ui.SplashActivity"
            android:theme="@style/SplashTheme"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.ConversationsActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:minWidth="300dp"
            android:minHeight="300dp"
            android:exported="true"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name=".ui.ScanActivity"
            android:screenOrientation="portrait"
            android:exported="true"
            android:theme="@style/ConversationsTheme.FullScreen"
            android:windowSoftInputMode="stateAlwaysHidden" />
        <activity
            android:name=".ui.UriHandlerActivity"
            android:label="@string/app_name"
            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="xmpp" />
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="https" />
                <data android:host="im.app.in" />
                <data android:pathPrefix="/i/" />
                <data android:pathPrefix="/j/" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SENDTO" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:scheme="imto" />
                <data android:host="jabber" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.StartConversationActivity"
            android:label="@string/title_activity_start_conversation"
            android:launchMode="singleTop"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.SettingsActivity"
            android:label="@string/title_activity_settings"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.ChooseContactActivity"
            android:label="@string/title_activity_choose_contact"
            android:exported="true" />
        <activity
            android:name=".ui.BlocklistActivity"
            android:label="@string/title_activity_block_list"
            android:exported="true"/>
        <activity
            android:name=".ui.ChangePasswordActivity"
            android:label="@string/change_password_on_server"
            android:exported="true"/>
        <activity
            android:name=".ui.ChooseAccountForProfilePictureActivity"
            android:enabled="false"
            android:label="@string/choose_account"
            android:exported="true">
            <intent-filter android:label="@string/set_profile_picture">
                <action android:name="android.intent.action.ATTACH_DATA" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.ShareViaAccountActivity"
            android:label="@string/title_activity_share_via_account"
            android:launchMode="singleTop"
            android:exported="true" />
        <activity
            android:name=".ui.EditAccountActivity"
            android:launchMode="singleTop"
            android:exported="true"
            android:windowSoftInputMode="stateHidden|adjustResize" />
        <activity
            android:name=".ui.ConferenceDetailsActivity"
            android:label="@string/action_muc_details"
            android:exported="true"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name=".ui.ContactDetailsActivity"
            android:exported="true"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name=".ui.PublishProfilePictureActivity"
            android:label="@string/mgmt_account_publish_avatar"
            android:exported="true"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name=".ui.PublishGroupChatProfilePictureActivity"
            android:exported="true"
            android:label="@string/group_chat_avatar" />
        <activity
            android:name=".ui.ShareWithActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="*/*" />
            </intent-filter>

            <!-- the value here needs to be the full class name; independent of the configured applicationId -->
            <meta-data
                android:name="android.service.chooser.chooser_target_service"
                android:value="eu.siacs.conversations.services.ContactChooserTargetService" />
        </activity>
        <activity
            android:name=".ui.TrustKeysActivity"
            android:label="@string/trust_omemo_fingerprints"
            android:exported="true"
            android:windowSoftInputMode="stateAlwaysHidden" />
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:exported="true"
            android:theme="@style/Base.Theme.AppCompat" />
        <activity android:name=".ui.MemorizingActivity"
            android:exported="true" />
        <activity
            android:name=".ui.MediaBrowserActivity"
            android:exported="true"
            android:label="@string/media_browser" />

        <service android:name=".services.ExportBackupService" android:exported="true"/>
        <service android:name=".services.ImportBackupService" android:exported="true"/>
        <service
            android:name=".services.ContactChooserTargetService"
            android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"
            android:exported="true">
            <intent-filter>
                <action android:name="android.service.chooser.ChooserTargetService" />
            </intent-filter>
        </service>
        <service android:name=".services.CompulsoryUpdateService" android:exported="true"/>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.files"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
        <provider
            android:name=".services.BarcodeProvider"
            android:authorities="${applicationId}.barcodes"
            android:exported="false"
            android:grantUriPermissions="true" />

        <activity
            android:name=".ui.ShortcutActivity"
            android:label="@string/contact"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.MucUsersActivity"
            android:exported="true"
            android:label="@string/group_chat_members" />
        <activity
            android:name=".ui.ChannelDiscoveryActivity"
            android:exported="true"
            android:label="@string/discover_channels" />
        <activity
            android:name=".ui.RtpSessionActivity"
            android:autoRemoveFromRecents="true"
            android:exported="true"
            android:launchMode="singleInstance"
            android:supportsPictureInPicture="true" />
    </application>

</manifest>

我的第二个清单文件:

<?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="eu.siacs.conversations">

    <application tools:ignore="GoogleAppIndexingWarning">
        <activity
            android:name=".ui.ManageAccountActivity"
            android:label="@string/title_activity_manage_accounts"
            android:launchMode="singleTask"
            android:exported="true"/>
        <activity
            android:name=".ui.MagicCreateActivity"
            android:label="@string/create_new_account"
            android:launchMode="singleTask"
            android:exported="true"/>
        <activity
            android:name=".ui.EasyOnboardingInviteActivity"
            android:label="@string/invite_to_app"
            android:launchMode="singleTask" />
        <activity
            android:name=".ui.ImportBackupActivity"
            android:label="@string/restore_backup"
            android:launchMode="singleTask"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="application/vnd.conversations.backup" />
                <data android:scheme="content" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="application/vnd.conversations.backup" />
                <data android:scheme="file" />
            </intent-filter>
            <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="content" />
                <data android:host="*" />
                <data android:mimeType="*/*" />
                <data android:pathPattern=".*\.ceb" />
                <data android:pathPattern=".*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\..*\..*\..*\.ceb" />
            </intent-filter>
            <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="file" />
                <data android:host="*" />
                <data android:mimeType="*/*" />
                <data android:pathPattern=".*\.ceb" />
                <data android:pathPattern=".*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\..*\..*\.ceb" />
                <data android:pathPattern=".*\..*\..*\..*\..*\..*\..*\.ceb" />
            </intent-filter>
        </activity>
    </application>
</manifest>

我的 gradle 文件:

import com.android.build.OutputFile

// Top-level build file where you can add configuration options common to all
// sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.5.21"
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath 'com.google.gms:google-services:4.3.8'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'

repositories {
    google()
    mavenCentral()
    jcenter()
    maven { url 'https://jitpack.io' }
}

configurations {
    conversationsFreeCompatImplementation
}

dependencies {
    implementation 'androidx.viewpager:viewpager:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    implementation 'org.sufficientlysecure:openpgp-api:10.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.exifinterface:exifinterface:1.3.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'androidx.emoji:emoji:1.1.0'
    implementation 'com.google.android.material:material:1.4.0'
    conversationsFreeCompatImplementation 'androidx.emoji:emoji-bundled:1.1.0'
    implementation 'org.bouncycastle:bcmail-jdk15on:1.64'
    //zxing stopped supporting Java 7 so we have to stick with 3.3.3
    //https://github.com/zxing/zxing/issues/1170
    implementation 'com.google.zxing:core:3.4.1'
    implementation 'de.measite.minidns:minidns-hla:0.2.4'
    implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
    implementation 'org.whispersystems:signal-protocol-java:2.8.1'
    implementation 'com.makeramen:roundedimageview:2.3.0'
    implementation "com.wefika:flowlayout:0.4.1"
    implementation 'net.ypresto.androidtranscoder:android-transcoder:0.3.0'
    implementation 'org.jxmpp:jxmpp-jid:1.0.1'
    implementation 'org.osmdroid:osmdroid-android:6.1.10'
    implementation 'org.hsluv:hsluv:0.2'
    implementation 'org.conscrypt:conscrypt-android:2.5.2'
    implementation 'me.drakeet.support:toastcompat:1.1.0'
    implementation "com.leinardi.android:speed-dial:3.2.0"

    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-gson:2.9.0"
    implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
    implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2'

    implementation 'com.google.guava:guava:30.1.1-android'
    implementation 'org.webrtc:google-webrtc:1.0.32006'

    // Lifecycle Helper
    implementation "androidx.activity:activity-ktx:1.3.0-rc02"
    implementation "androidx.fragment:fragment-ktx:1.3.6"

    //Navigation
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

    //CardView
    implementation "androidx.cardview:cardview:1.0.0"

    //Country Code Picker
    implementation 'com.hbb20:ccp:2.5.3'

    //Firebase
    implementation 'com.google.firebase:firebase-bom:28.3.0'
    implementation 'com.google.firebase:firebase-auth-ktx:21.0.1'
    implementation 'androidx.browser:browser:1.3.0'

    //OTP view
    implementation 'com.github.mukeshsolanki:android-otpview-pinview:2.1.2'

    //Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    //Gson
    implementation 'com.google.code.gson:gson:2.8.7'

    //Multidex
    implementation 'androidx.multidex:multidex:2.0.1'

    //Round Image
    implementation 'de.hdodenhof:circleimageview:3.1.0'

    // Button with image and text
    implementation 'com.github.Omega-R:OmegaCenterIconButton:0.0.4@aar'

    //Razor pay
    implementation 'com.razorpay:checkout:1.6.10'

    //Mixpanel Tracking
    implementation 'com.mixpanel.android:mixpanel-android:5.9.1'

    //Loading screen
    implementation 'com.wang.avi:library:2.1.3'

    //Loading
    implementation 'com.wang.avi:library:2.1.3'

    //Form
    implementation 'com.quickbirdstudios:surveykit:1.1.0'
}

ext {
    travisBuild = System.getenv("TRAVIS") == "true"
    preDexEnabled = System.getProperty("pre-dex", "true")
    abiCodes = ['armeabi-v7a': 1, 'x86': 2, 'x86_64': 3, 'arm64-v8a': 4]
}

android {
    compileSdkVersion 31

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 31
        versionCode 44
        versionName "2.0.4"
        multiDexEnabled = true
        archivesBaseName += "-$versionName"
        applicationId "com.app.app"
        resValue "string", "applicationId", applicationId
        def appName = "app"
        resValue "string", "app_name", appName
        buildConfigField "String", "APP_NAME", "\"$appName\""
    }

    splits {
        abi {
            universalApk true
            enable true
        }
    }

    configurations {
        compile.exclude group: 'org.jetbrains' , module:'annotations'
    }

    dataBinding {
        enabled true
    }

    dexOptions {
        // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
        preDexLibraries = preDexEnabled && !travisBuild
        jumboMode true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    flavorDimensions("mode", "distribution", "emoji")

    productFlavors {

        conversations {
            dimension "mode"
        }
        free {
            dimension "distribution"
            versionNameSuffix "+f"
        }
        compat {
            dimension "emoji"
            versionNameSuffix "c"
        }
    }

    sourceSets {
        conversationsFreeCompat {
            java {
                srcDir 'src/freeCompat/java'
                srcDir 'src/conversationsFree/java'
            }
        }
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            versionNameSuffix "r"
        }
        debug {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            versionNameSuffix "d"
        }
    }


    if (new File("signing.properties").exists()) {
        Properties props = new Properties()
        props.load(new FileInputStream(file("signing.properties")))

        signingConfigs {
            release {
                storeFile file(props['keystore'])
                storePassword props['keystore.password']
                keyAlias props['keystore.alias']
                keyPassword props['keystore.password']
            }
        }
        buildTypes.release.signingConfig = signingConfigs.release
    }

    lintOptions {
        disable 'MissingTranslation', 'InvalidPackage','AppCompatResource'
    }

    subprojects {

        afterEvaluate {
            if (getPlugins().hasPlugin('android') ||
                    getPlugins().hasPlugin('android-library')) {

                configure(android.lintOptions) {
                    disable 'AndroidGradlePluginVersion', 'MissingTranslation'
                }
            }

        }
    }

    packagingOptions {
        exclude 'META-INF/BCKEY.DSA'
        exclude 'META-INF/BCKEY.SF'
    }

    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def baseAbiVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
            if (baseAbiVersionCode != null) {
                output.versionCodeOverride = (100 * variant.versionCode) + baseAbiVersionCode
            }
        }

    }
}

我不确定你用什么来编码,但为了在 Android Studio 中设置它,打开你的项目清单并在“activity”部分下,放 android:exported="true"(如果您愿意,则为 false)。 I have attached an example.

我遇到了这个问题,我使用的库之一没有正确设置它。

查找位置

首先,我们需要找到错误的确切位置and/or,
这可以通过不同的方法来完成(见下文)。

通过检查合并清单查找 (方法 #1)

您可以通过以下步骤找到它:

  • 将目标 SDK 设置为 30(以消除 31+ 错误)。

  • 打开应用程序的清单 (AndroidManifest.xml) 并单击编辑窗格底部的“Merged Manifest”选项卡:

    Which if you configure build.gradle like:

    allprojects {
       buildDir = "${rootProject.rootDir}/build/${project.name}"
    }
    

    Something similar should be in a sub-path like:

    build/my-app/intermediates/merged_manifest/debug/AndroidManifest.xml
    
  • 转到所有库的单独清单文件(如果创建了合并清单,则可以跳过此步骤,您可以直接查看合并清单)

  • 搜索是否有 条目 类型 activity、服务、接收者或提供者不具有 exported 属性, 对于每个条目,请遵循下面的“修复找到的条目”部分(或查看如何设置 exported 属性)。

  • 将目标 SDK 设置回 31(或更改为 30 之前的任何值)。

通过控制台日志查找 (方法 #2)

  • 在 Git-bash 运行 中类似于:

    ./gradlew assembleDebug --stacktrace --info | tee my-logs.txt
    
  • 打开 my-logs.txt 文件(上一步创建的文件,在您首选的文本编辑器中)。

  • 现在,确切位置在日志中 隐藏, 因此在创建的 my-logs.txt 文件中搜索, 对于这些关键字:

    • activity#
    • service#
    • receiver#
    • provider#
  • 应该找到如下内容:

activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity
ADDED from [androidx.test:core:1.2.0] C:\Users\Admin\.gradle\caches\transforms-39730c74fe4dc9f8fd991eb4d1c2adc\transformed\jetified-core-1.2.0\AndroidManifest.xml:27:9-33:20
  • 打开前面步骤确实找到的 AndroidManifest.xml 文件,搜索是否有任何类型为 activityservice、[=30 的 条目 =],或没有 exported 属性的 provider,请参阅下面的“修复找到的条目”部分(了解如何设置每个条目的 exported 属性)。

Note that (at time of writting) passing --stacktrace alone did not include location info ;-)

修复找到的条目

如果找到条目的真实(不是构建生成的)源在根项目的清单中(或您可以更改的地方), 直接在其中设置exported属性对应的需求(一般是false),如:

<receiver
    android:name="<name_of_the_entry>"
    android:exported="false or true"
    tools:node="merge" />

Note that both android:exported="..." and tools:node="merge" are set above.

但如果找到的条目的规范是写在第三方库的清单中的(这是您无法更改的真实来源), 通过将其添加到我们的根项目清单来覆盖所述库的规范,例如:

<provider
    android:name="com.squareup.picasso.PicassoProvider"
    android:exported="false"
    tools:node="merge"
    tools:overrideLibrary="com.squareup.picasso.picasso" />

Note that this time tools:overrideLibrary="..." is set as well.

For more information see Documentation,
and/or Similar issue in a SDK.

构建失败后转到 AndroidManifest.xml 并在底部单击合并清单查看哪些活动具有 intent-filter 但没有 exported=true 属性。 或者您可以只获取出错的活动。

使用 android:exported="true" 和应用程序 tools:node="merge" 将这些活动添加到您的应用程序清单中,这会将导出的属性添加到活动中并给出错误。 示例:

     <activity
                android:name="<activity which is giving error>"
                android:exported="true"
                tools:node="merge" />

你将不得不这样做一次,一旦库开发人员更新了他们的库,你就可以删除它。

修复此类问题可能有点麻烦,因为 IDE 没有提供错误的详细信息,它只是告诉您有一个 Activity、没有导出的接收器或服务参数,但不会告诉您它是哪一个。正如 Jakos 推荐的那样,您可以手动检查合并的清单,或者使用 this script 以防生成的清单太大。

之后,如果它是项目的一部分,您可以通过添加导出的属性来修改受影响的条目,或者如果它是库的一部分,则覆盖它:

<activity android:name="name_of_the_activity_inside_library>"
    android:exported="false|true"
    tools:node="merge" />

更新: 清单合并任务似乎在以 android S 为目标时没有生成清单而失败,并且检测到此问题,因此我的建议是使用低于 31 的 targetSdk 编译应用程序,然后手动或使用检查生成的清单我链接的脚本。 (您可以在构建文件夹中或通过 inspecting 生成的 apk 找到合并的清单)

临时解决方案

将compileSdk、targetSdk更改为

compileSdk 30 targetSdk 30

在gradle文件中

我碰巧知道 android 12 中的那个问题。 Android SDK 中已经存在错误。在您的问题的解决方案中,您可以在 android studio 和 运行 方法中添加一个文件。

Enable android exported file

然后 运行 def 方法并尝试构建。 这是久经考验的工作方法。

我收到这个针对 sdk 31 抛出的错误,发现解决方案在我的 build.gradle 文件中。我在我的撰写测试依赖项上使用 implementation 而不是 testImplementation.

我知道这似乎不相关,但是当您查看带有误用测试依赖项的合并清单时,您会看到为 InstrumentedActivity 添加的标签将缺少 exported=true 字段。

检查您的 build.gradle 文件:

debugImplementation "androidx.fragment:fragment-testing:<version>"

如果存在,将其更改为:

androidTestImplementation "androidx.fragment:fragment-testing:<version>"

它应该一直是 androidTestImplementation,但之前存在一些依赖性问题,因此有必要使用 debugImplementation 作为解决方法。 IDE 实际上提示您这样做。但显然它已针对 SDK 31 修复,如果您将其保留为 debugImplementation,您会收到 android:exported-missing manifest 错误,该错误来自依赖包中的 manifest.xml

因为目标 sdk 更新到 31 android 12 所以你必须在 manifest.xml 的 activity 午餐器中做 android 导出

 android:exported="true"

对于插桩测试,如果您使用的是组合测试,请确保除了 compose.ui 依赖项之外还添加 androidx.test.ext:junit

androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.4"

只需更新所有依赖项,它应该可以工作

引用 official docs about this behavior change in android 12,您应该查找包含 intent-filter 的活动,这些活动需要通过显式设置 android:exported.

的值来更新

构建日志应准确指向 activity with undeclared exported flag 停止构建。您应该在 install gradle 命令的控制台输出的最后几行之间看到类似这样的内容:

> java.util.concurrent.ExecutionException: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/xxxxx.tmp/base.apk (at Binary XML file line #129): YOUR.FULLY.QUALIFIED.NAME.FAILING.ACTIVITY: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present

YOUR.FULLY.QUALIFIED.NAME.FAILING.ACTIVITY 应该指向阻止您构建的特定 activity。

这里也是设置android:exportedlink to the implications

我的问题是 test:core:1.3.0(见屏幕截图)。

我必须覆盖此库的清单条目并声明 android:exported 属性:

<activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
android:exported="true"
tools:node="merge"/>

<activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
android:exported="true"
tools:node="merge"/>

<activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
android:exported="true"
tools:node="merge"/>

如果您确定要将 exported 添加到清单文件中的每个元素,但仍然出现此错误,只需:

  1. 切换到项目目录并在app\build\intermediates\merged_manifest
  2. 中打开合并的清单文件
  3. 搜索任何包含 intent-filter 但没有导出属性的组件
  4. 通过将其复制到主清单文件来覆盖清单文件中的此组件

提示:如果找不到合并文件,因为它已经无法生成它。临时降级到 targetSdkVersion 30 和 compileSdkVersion 30 并构建项目以生成此文件,然后按照上述步骤升级到 31 (android 12)

如果您的应用面向 Android12 或更高版本,您必须在应用的清单文件中声明这些属性标签。 如果应用程序组件包含 LAUNCHER 类别,请将 android:exported 设置为 true。

 <activity
        android:name="com.test.activity.SplashActivity"
        android:clearTaskOnLaunch="true"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:exported="true">

同时检查 Android 清单中的接收器或服务,如果您使用任何接收器或服务,根据要求设置 android:exported="true" 或 false。

   <receiver
        android:name="com.test.receiver.ShareReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.test.fcm.android.action.broadcast" />
        </intent-filter>
    </receiver>

   <service
        android:name="com.google.android.gms.tagmanager.InstallReferrerService"
        android:exported="true" />

同时更新所有 gradle 依赖项。

我已根据要求更新了以下依赖项。

testImplementation 'junit:junit:4.13.2' 
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.razorpay:checkout:1.6.15'

希望对你也有帮助。

我的问题是我们使用的是较旧的刀柄版本 2.38.1:

"com.google.dagger:hilt-android:2.38.1"
"com.google.dagger:hilt-android-gradle-plugin:2.38.1"
"com.google.dagger:hilt-android-compiler:2.38.1"
"com.google.dagger:hilt-android-testing:2.38.1"

"com.google.dagger:hilt-android-testing:2.38.1" 底层依赖于核心测试库 1.3.0,它确实设置了导出的属性。

要解决此问题,请确保您使用的是最新的匕首柄版本(2.40.5 有效):

"com.google.dagger:hilt-android:2.40.5"
"com.google.dagger:hilt-android-gradle-plugin:2.40.5"
"com.google.dagger:hilt-android-compiler:2.40.5"
"com.google.dagger:hilt-android-testing:2.40.5" 

targetSdkVersion 改回 30
你可以在 31 离开 compileSdkVersion
然后点击运行

找到这个解决方案 here,适合我。这是官方 razorpay github 给出的。他们提到他们会在下一个版本中修复它。

<receiver
    android:name="com.razorpay.RzpTokenReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="rzp.device_token.share" />
    </intent-filter>
</receiver>

<activity
    android:name="com.razorpay.CheckoutActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:exported="true"
    android:theme="@style/CheckoutTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <data
            android:host="rzp.io"
            android:scheme="io.rzp" />
    </intent-filter>
</activity>

情况 1:没有子模块或库

此问题始于 SDK 31。如果您没有任何库或子模块,请添加

android:exported="true" <!-- or false as required -->

您可以右键单击标签,Android Studio 会向您推荐。

情况 2:使用子模块或库

如果您有其他要导入的库或模块,您也必须覆盖它们。为此,请参阅选项卡 'Merged Manifest'。 或者您可以打开

<ProjectRoot>/app/build/intermediates/merged_manifest/<your flavor>/AndroidManifest.xml

在编辑器中。我更喜欢第二种方法,因为合并清单不允许从 Android Studio 搜索。

  1. 复制 或任何其他导致构建错误的内容。
  2. 将它们粘贴到主清单
  3. 根据需要添加 android:exported="true" 或 android:exported="false"
  4. 重建

情况3:如果None上面的作品

如果上述 none 有效,您将不得不等到您的图书馆提供商做出必要的更改。在他们做出更改之前,您可以将 SDK 版本恢复到 30 或更低版本。降低 sdk 应该可以暂时解决问题。

如果你正在使用 flutter ,升级 flutter_local_notifications 到最新版本(现在是 9.3.2)可能会解决这个错误..

<activity
     android:name=".MainActivity"
     android:exported="true" <** add this line on AndroidManifest.xml**
     android:launchMode="singleTop"
     android:theme="@style/LaunchTheme"
 </activity>

对于仍在使用Flutter有问题的人,除了在应用程序的