在 Android 12 中调试应用程序时,应用程序崩溃了。
问题:您上传的 APK 或 Android App Bundle 具有带有意图过滤器的活动、活动别名、服务或广播接收器,但未设置“android:exported”属性。此文件无法安装在 Android 12 或更高版本上。请参阅developer.android.com/about/versions/12/behavior-changes-12#exported
我的 AndroidManifest.xml 文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.c4life.guardianangel">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<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"/>
<application
tools:replace="android:label"
android:label="GA"
android:exported="true"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="[insert API key here]"/>
<activity
android:name=".MainActivity"
android:exported="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">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name="changjoopark.com.flutter_foreground_plugin.FlutterForegroundService" android:exported="false"/>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-sdk
android:targetSdkVersion="30"
tools:overrideLibrary="changjoopark.com.flutter_foreground_plugin" />
Run Code Online (Sandbox Code Playgroud) android android-manifest google-play google-play-console android-12
在运行 Android 12 的模拟器上测试 Flutter 应用程序时,我会定期(大约每秒)在日志中看到类似这样的行:
D/EGL_emulation(32175): app_time_stats: avg=312.93ms min=133.69ms max=608.57ms count=4
Run Code Online (Sandbox Code Playgroud)
它们是什么意思,我该如何关闭它们?我从未在 Android 11 模拟器上见过它们,所以我猜测它与 Android 12 有关?
我注意到 Pixel 5 和 Pixel 4a(均在 Android 12 上)有一个例外(Firebase Crashlytics),没有其他设备,仅发生两次,每个设备一次。
这是什么意思?Android 11 和 12 对于前台服务的使用规则相同,但 Android 11 没有问题。这是 Pixel 的错误吗?
来自 Firebase Crashlytics:
Fatal Exception: android.app.ForegroundServiceStartNotAllowedException
startForegroundService() not allowed due to mAllowStartForeground false: service com.*.*/.service.RecorderService
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
androidx.core.content.ContextCompat.startForegroundService (ContextCompat.java:6)
MyAppPackageHidden.service.RecorderService$Companion.startService (RecorderService.java:2)
MyAppPackageHidden.ui.rec.RecActivity$getConnectionRecorderService$1.onServiceConnected (RecActivity.java:4)
android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2077)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
Fatal Exception: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service MyAppPackageHidden/.service.RecorderService
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
at android.os.Parcel.readParcelable(Parcel.java:3333)
at android.os.Parcel.createExceptionOrNull(Parcel.java:2420)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5971)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1847)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1823)
at …Run Code Online (Sandbox Code Playgroud) 我发现我正在启动的新应用程序出现奇怪的问题。我正在利用新的 Android 12 启动画面 API 来创建启动画面,并按照Google 提供的指南进行操作。我在项目中包含了 core-splashscreen,以提供与旧版本 Android 操作系统的兼容性。当我运行该应用程序时,我会在 API 30 等旧操作系统版本上看到预期的启动屏幕,但当我在 API 31 上运行它时,我提供的启动屏幕图标不会显示。显示了我指定的背景颜色,但根本不存在图标。我已经尝试使用可绘制资源和 mipmap 进行此操作,但没有任何效果。我很困惑,因为我找到的每个教程都显示了我所遵循的相同步骤以及他们工作启动屏幕的屏幕截图,但我没有任何运气。
对于上下文,这里是我对 v31 的启动屏幕样式定义:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">@color/orange_7A</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我对所有其他操作系统版本都有相同的样式,除了我使用“windowSplashScreenAnimatedIcon”而不是“android:windowSplashScreenAnimatedIcon”。我尝试过 v31 在项目名称前面有或没有“android:”,但都不起作用。这是我的 MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
MyVeevaTheme {
Login()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还在 AndroidManifest.xml 中将“android:theme”属性设置为我的启动样式。我知道正在应用启动样式,因为它尊重背景颜色,但由于某种原因它没有显示图标,即使图标在旧操作系统版本中显示良好。预先感谢您可以提供的任何帮助。
应用程序在运行时崩溃并出现以下错误:
java.lang.IllegalArgumentException:maa.abc:针对 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于可变的 PendingIntent 时才使用 FLAG_MUTABLE,例如,如果需要与内联回复或气泡一起使用。在 android.app.PendingIntent.checkFlags(PendingIntent.java:375) 在 android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) 在 android.app.PendingIntent.getBroadcast(PendingIntent.java:632) 在 com.google。 android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1373) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1329) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager。 (PlayerNotificationManager.java:643) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.(PlayerNotificationManager.java:529) 在 com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:456) 在 com .google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:417)
我尝试了所有可用的解决方案,但应用程序在 Android 12 上仍然崩溃。
@Nullable
@Override
public PendingIntent createCurrentContentIntent(@NonNull Player player) {
Intent intent = new Intent(service, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(service, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
Run Code Online (Sandbox Code Playgroud) 我在 Windows 10 上使用 Android Studio 2020.3.1 Patch 2,并且运行 Android 12 模拟器。
我试图使用 Google Chrome 简单地加载任何网页,但是所发生的只是出现进度条,但无论我尝试加载哪个网站,都不会加载任何内容。发生的另一件事是,有时 Chrome 只是停留在加载屏幕上,并且在启动时并未完成加载。
我已经验证模拟器可以访问互联网,事实上,我可以使用默认情况下模拟器中存在的 Webview Browser Tester 应用程序来加载网页。
被这个问题难住了,非常感谢任何帮助。
面向 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。我在将目标 SDK 更新到 31 后得到它。错误总是出现在 AlarmPingSender 之后。但我不知道任何使用 AlarmPingSender 的类。
2021-10-31 10:43:04.990 17031-17341/com.app.mobile D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.com.app.mobile-2e24ccbde048f2e91635651784
2021-10-31 10:43:04.993 17031-17341/com.app.mobile E/AndroidRuntime: FATAL EXCEPTION: MQTT Rec: com.app.mobile-2e24ccbde048f2e91635651784
Process: com.app.mobile, PID: 17031
java.lang.IllegalArgumentException: com.app.mobile: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it …Run Code Online (Sandbox Code Playgroud) android kotlin android-pendingintent android-workmanager android-12
从 Android 12 开始,Google 会显示带有应用图标的 Toast 消息。
我的应用程序有启动器图标。Android 12 初始屏幕正确显示应用程序图标。
通过代码显示 toast
Toast.makeText(this, "Show simple toast", Toast.LENGTH_LONG).show()
Run Code Online (Sandbox Code Playgroud)
编译SdkVersion/targetSdkVersion 31
android 模拟器 Google play Intel x86 Atom_64 系统映像 API 级别 31,修订版 8。
如何更改此默认 toast 图标?
我已添加android:exported="true"到清单中唯一的活动,但在将编译 sdk 和目标 sdk 版本更新为 31 后仍然出现以下错误。我还尝试重建项目、使缓存无效并重新启动,但这没有帮助
错误- 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.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.abc">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".framework.presentation.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.xyz.presentation.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
play-services-auth-api-phone:17.4.0 清单、leakcanary-android:2.0-alpha-3 清单、firebase-auth-interop:20.0.0 清单、生命周期-viewmodel:2.3.1 清单、浏览器:1.0。 0 …
android manifest android-manifest targetsdkversion android-12
android-12 ×10
android ×9
flutter ×2
exoplayer2.x ×1
google-play ×1
java ×1
kotlin ×1
logcat ×1
manifest ×1
toast ×1