【发布时间】:2022-05-04 00:01:25
【问题描述】:
在 android 12 中调试应用程序时,应用程序崩溃了。
【问题讨论】:
标签: flutter android-12
在 android 12 中调试应用程序时,应用程序崩溃了。
【问题讨论】:
标签: flutter android-12
Android 12 要求您在主 Activity 中添加一段代码
转到您的项目文件夹并打开 AndroidManifest.xml 文件
在活动中添加以下代码
android:exported="true"
例子
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
</activity>
【讨论】:
android:exported="true" 是什么意思/做什么?
在 AndroidManifest.xml 中添加 android:exported="true":
<manifest ...>
<application ...>
<activity
android:exported="true"
【讨论】:
android:exported="true" 解决了我在 Flutter 中构建的问题
感谢@rahul-kavati。
对于 Xamarin/MAUI,它是 ActivityAttribute 上的一个属性,像这样使用 [Activity(Label = "MsalActivity", Exported = true)]
【讨论】:
在 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 是将应用程序的组件暴露给外部的方法之一。这是因为我的应用程序的组件可以通过隐式意图的解析来执行。
另一方面,在很多情况下,它仅用于在我的应用程序内部执行具有隐式意图的组件,但由于未设置导出而暴露于外部,这可能会影响隐含意图的解决。 .
【讨论】:
<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>
【讨论】:
如果您使用任何意图过滤器或服务,它必须具有android:export 属性
【讨论】:
是的,在 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>
【讨论】: