错误:android:需要为元素显式指定导出<activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity>

问题描述 投票:0回答:5

我有这个错误“..app\src\main\AndroidManifest.xml:27:9-33:20 错误: android:exported 需要为元素 显式指定。当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要为

android:exported
指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported

...app\src\main\AndroidManifest.xml:34:9-40:20 错误: android:exported 需要为元素 显式指定。当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要为

android:exported
指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported

...app\src\main\AndroidManifest.xml:41:9-47:20 错误: android:exported 需要为元素 显式指定。当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要为

android: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.example.part3_2">

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

    <application
        android:allowBackup="true"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Part3_2"
        tools:ignore="DataExtractionRules">
        <activity
            android:name=".MainActivity">
        </activity>
        <activity
            android:name=".MainActivity2"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <service
            android:name=".OverlayService"
            android:exported="false"
            android:enabled="true"
            android:foregroundServiceType="mediaProjection">
        </service>
    </application>

</manifest>

构建.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

android {
    compileSdk 30

    defaultConfig {
        applicationId "com.example.part3_2"
        minSdk 28
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

}

ext{
    fragment_version = "1.3.0-alpha07"
    activity_version = "1.3.0"
}
dependencies {


    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
//    implementation 'androidx.fragment:fragment-ktx:1.6.0'
    implementation("androidx.fragment:fragment-ktx:$fragment_version")
    debugImplementation("androidx.fragment:fragment-testing:$fragment_version")
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.0'
    implementation 'com.google.firebase:firebase-firestore-ktx:24.3.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation("androidx.activity:activity-ktx:$activity_version")

    androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.4"
}

repositories {
    google()
    mavenCentral()
}
kotlin android-manifest
5个回答
1
投票

我通过添加这一行解决了这个问题:

android:exported="true"

在我的 androidManifest.xml 文件中

<activity
            android:name=".MainActivity"
            android:exported="true"
            ...

0
投票

这也可能发生在 gradle 自动下载的库或依赖项中。 尝试运行删除依赖项或库,直到找到引发此错误的依赖项或库。

如果您找到解决方案,请告诉我。谢谢你。


0
投票

对于即使在清单中添加

android:exported="true|false"
后仍然遇到此问题的任何人。

升级到android 12后,还需要升级测试依赖项。对我来说,困扰的是

androidx.test:core:1.2.0
,需要升级为
androidx.test:core:1.4.0


-1
投票

我在我的 flutter 项目中也遇到了这个错误,我通过添加这个来解决。 Android 清单中的应用程序部分。

        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
            android:exported="false" />
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
            android:exported="false" />
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
            android:exported="false" />

希望这有帮助!!


-2
投票

每个组件上必须有导出标签,该标签已在清单文件中声明,而您在 MainActivity 组件上缺少它。

将其更改为

<activity
    android:name=".MainActivity">

<activity
    android:name=".MainActivity"
    android:exported="false">
</activity>
© www.soinside.com 2019 - 2024. All rights reserved.