I recently had to migrate to use embedding v2 for my flutter app. I can run my app on the emulator and it works fine, but when I try to run it on a real device (Android) it crashes immediately. The screen flashes up with the white background, but immediately crashes, so it's literally just a flash of the white screen. I'm absolutely lost on how to fix it. Happy to share any parts of the code if there is something you think might need looking at.
I am assuming the issue is to do with the migration to embedding v2 as I've only made minor changes elsewhere since the last app version.
Or if anyone has any tips on how I might go about debugging this? I have a real device attached, but no errors occur. It just shows installing on the IDE, but the app crashes on the phone.
EDIT: After a Flutter Clean and running the app on a real device again. I get the following:
E/AndroidRuntime(13098): FATAL EXCEPTION: pool-3-thread-1
E/AndroidRuntime(13098): Process: packagename, PID: 13098
E/AndroidRuntime(13098): java.lang.IllegalArgumentException: packagename: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(13098): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
E/AndroidRuntime(13098): at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime(13098): at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
E/AndroidRuntime(13098): at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
E/AndroidRuntime(13098): at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:196)
E/AndroidRuntime(13098): at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:128)
E/AndroidRuntime(13098): at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:93)
E/AndroidRuntime(13098): at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
E/AndroidRuntime(13098): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(13098): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(13098): at java.lang.Thread.run(Thread.java:920)
And this is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package name">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<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.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https"/>
</intent>
<intent>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
</intent>
<intent>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="*/*"/>
</intent>
<intent>
<action android:name="android.intent.action.MAIN"/>
</intent>
</queries>
<application
android:name="${applicationName}"
android:label="Local Weather"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="packagename.action.LAUNCH"/>
</intent-filter>
</activity>
<receiver android:name="WeatherWidgetProvider"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/home_widget_info"/>
</receiver>
<receiver android:name="LW01WidgetProvider"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/lw01_widget_info"/>
</receiver>
<receiver android:name="LW02WidgetProvider"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/lw02_widget_info"/>
</receiver>
<receiver android:name="LW03WidgetProvider"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/lw03_widget_info"/>
</receiver>
<receiver android:name="es.antonborri.home_widget.HomeWidgetBackgroundReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.resortstylebeanbags.localweatherau.action.BACKGROUND"/>
</intent-filter>
</receiver>
<service android:name="es.antonborri.home_widget.HomeWidgetBackgroundService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"/>
<!-- 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>