【问题标题】:Error:android:exported needs to be explicitly specified for element<activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity>错误:android:exported 需要为 element<activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity> 显式指定
【发布时间】:2022-09-29 22:46:41
【问题描述】:

我有这个错误 \"..app\\src\\main\\AndroidManifest.xml:27:9-33:20 错误: android:exported 需要为元素 <activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity> 显式指定。当相应组件定义了 Intent 过滤器时,面向 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 需要为元素 <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity> 显式指定。当对应的组件定义了意图过滤器时,面向 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 需要为元素 <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity> 显式指定。当相应组件定义了 Intent 过滤器时,面向 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


    【解决方案1】:

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

    改变这个从

    <activity
        android:name=".MainActivity">
    

    <activity
        android:name=".MainActivity"
        android:exported="false">
    </activity>
    

    【讨论】:

      【解决方案2】:

      我在我的颤振项目中也遇到了这个错误,我通过添加这个来解决。 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" />

      希望这有帮助!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-07-13
        • 2021-11-28
        • 2021-10-03
        • 2022-07-27
        • 2022-08-12
        • 2022-09-23
        • 2022-01-21
        • 2022-01-17
        相关资源
        最近更新 更多