【问题标题】:android:exported needs to be explicitly specified for <receiver>. Apps targeting Android 12 and higher In Flutterandroid:exported 需要为 <receiver> 显式指定。在 Flutter 中针对 Android 12 及更高版本的应用
【发布时间】:2022-06-11 02:18:36
【问题描述】:
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : android:exported needs to be explicitly specified for <receiver>. 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.

这个错误是在我的 Flutter 应用程序中引发的。我在所有活动和服务中设置了android:exported="true"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CALL_LOG"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_CALL_LOG"></uses-permission>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.GET_TASKS" />

    <application
        android:label="My APP"
        android:usesCleartextTraffic="true"
        android:requestLegacyExternalStorage="true"
        android:hardwareAccelerated="false"
        android:largeHeap="true"
        android:icon="@mipmap/launcher_icon">

       <meta-data android:name="io.flutter.network-policy"
           android:resource="@xml/network_security_config"/>
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/rsoft_logo" />
        <activity
            android:usesCleartextTraffic="true"
            android:name=".MainActivity"
            android:exported="true"
            android:enabled="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <meta-data
                android:name="flutterEmbedding"
                android:value="2" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:exported="true"
            android:enabled="true"
            android:theme="@style/Theme.AppCompat.Dialog.MinWidth"
            android:name=".PopUpActivity"/>
        <receiver android:name=".CallReceiver"
            android:exported="true"
            android:enabled="true"
            android:permission="android.permission.BIND_JOB_SERVICE">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Reference Image

【问题讨论】:

标签: java android flutter dart


【解决方案1】:

请检查 build.gradle 文件:

androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.fragment:fragment-testing:1.4.1"
androidTestImplementation "androidx.test:core:1.4.0"

而且只需编辑接收器 > 导出:“false” 另一种方式:

1.首先将target sdk设置为30

2.然后进入合并清单

3.查找是否有任何活动、服务、接收者或提供者没有设置 android:exported。覆盖所有这些条目并将它们的 android:exported 设置为 true 或 false。

4.将目标sdk设置回31并运行项目

【讨论】:

    【解决方案2】:

    请制作

     android:exported="false"
    

    在除 MainActivity 之外的所有活动、服务、接收器中

    【讨论】:

      猜你喜欢
      • 2021-10-03
      • 2022-01-06
      • 2021-10-11
      • 2023-02-12
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 2022-01-21
      相关资源
      最近更新 更多