【问题标题】:Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]定位 S+(版本 31 及更高版本)要求在存在意图过滤器时定义 android:exported 的显式值]
【发布时间】:2022-05-04 00:01:25
【问题描述】:

在 android 12 中调试应用程序时,应用程序崩溃了。

【问题讨论】:

    标签: flutter android-12


    【解决方案1】:

    Android 12 要求您在主 Activity 中添加一段代码

    1. 转到您的项目文件夹并打开 AndroidManifest.xml 文件

    2. 在活动中添加以下代码

      android:exported="true"

    3. 例子

      <activity
           android:name=".MainActivity"
           android:exported="true"
           android:launchMode="singleTop"
           android:theme="@style/LaunchTheme"
       </activity>
      

    【讨论】:

    • 此属性必须在 标签内设置。
    • 您能否更具体地说明必须添加的位置?
    • 为什么需要它? android:exported="true" 是什么意思/做什么?
    • @instanceof 有关该属性的更多信息,请访问medium.com/androiddevelopers/…
    • 为了清楚起见,这个答案并不好。您需要在每个带有意图过滤器的活动和每个服务上使用此属性。再次感谢 Android 的那些无用更新,这些更新破坏了全球数百万个部署!你是冠军!
    【解决方案2】:

    AndroidManifest.xml 中添加 android:exported="true"

    <manifest ...>
      <application ...>
        <activity
            android:exported="true"
    

    【讨论】:

    • 通过在 app/src/main/AndroidManifest.xml 中放置 android:exported="true" 解决了我在 Flutter 中构建的问题
    【解决方案3】:

    感谢@rahul-kavati。

    对于 Xamarin/MAUI,它是 ActivityAttribute 上的一个属性,像这样使用 [Activity(Label = "MsalActivity", Exported = true)]

    【讨论】:

    • 当我添加这个时,我得到错误:System.InvalidOperationException: Duplicate attribute 但我已经搜索了我的所有代码并且 Exported 只定义了一次。有什么想法吗?
    • 也许你不止一次拥有它?
    • 这是一个 xamarin android 错误,github.com/xamarin/xamarin-android/issues/6463。该修复仅适用于 VS22,我仍在运行 VS19
    【解决方案4】:

    在 Android 11 及更低版本中,在 AndroidManifest 中声明 Activity、Service 或 Broadcast 接收器时,您没有显式声明 android:exported。由于默认值为exported=true,所以只需要在不想对外透露的时候声明exported=false即可。

    <activity android:name="com.example.app.backgroundService">
        <intent-filter>
            <action android:name="com.example.app.START_BACKGROUND" />
        </intent-filter>
    </activity>
    

    Android 12 更改:导出的显式声明 在 Android 12 设备上将 SDK API 31 (android 12) 设置为 Target sdk 的应用程序必须在声明 intent-filter 的 Activity 等组件中显式声明导出。否则会出现如下错误,安装失败。

    Targeting S+ (version 10000 and above) requires that an explicit value for
    android:exported be defined when intent filters are present
    The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
    Even for apps targeting SDK API 31, components without intent-filter can omit the exported declaration.
    

    您必须明确声明导出如下:

    <service android:name="com.example.app.backgroundService"
             android:exported="false">
        <intent-filter>
            <action android:name="com.example.app.START_BACKGROUND" />
        </intent-filter>
    </service>
    

    Intent-filter 是将应用程序的组件暴露给外部的方法之一。这是因为我的应用程序的组件可以通过隐式意图的解析来执行。

    另一方面,在很多情况下,它仅用于在我的应用程序内部执行具有隐式意图的组件,但由于未设置导出而暴露于外部,这可能会影响隐含意图的解决。 .

    【讨论】:

      【解决方案5】:

      在 AndroidManifest.xml 中

           <activity
              android:exported="true"
              android:name="com.YOU.APP.activities.MainActivity"
              android:launchMode="singleTask"
              android:hardwareAccelerated="true">
              <intent-filter>
                  <action android:name="android.intent.action.SEND" />
      
                  <category android:name="android.intent.category.DEFAULT" />
      
                  <data android:mimeType="text/plain" />
              </intent-filter>
          </activity>
      

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      【解决方案6】:

      如果您使用任何意图过滤器或服务,它必须具有android:export 属性

      【讨论】:

        【解决方案7】:

        是的,在 AndroidManifest.xml 中

         <activity
            android:exported="true" //here it is
            android:name="com.YOU.APP.activities.MainActivity"
            android:launchMode="singleTask"
            android:hardwareAccelerated="true">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
        
                <category android:name="android.intent.category.DEFAULT" />
        
                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-10-05
          • 2022-01-08
          • 1970-01-01
          • 1970-01-01
          • 2021-09-29
          • 2023-01-01
          • 2022-08-22
          相关资源
          最近更新 更多