I'm developing a Flutter app that uses the workmanager plugin for background tasks. The app works fine on iOS, but I'm encountering build issues on Android. Here's my setup:
Flutter Workmanager Build Issue on Android
Environment:
- Flutter Version: 3.x
- Workmanager Plugin: ^0.5.0
- Kotlin Version: 1.9.22
- Java Version: 17
- Target SDK: 34
- Min SDK: 26
Issue:
When building the Android app, the build process fails with the following error:
Error: Gradle build failed to produce an .apk file.
Steps Tried:
Updated Kotlin version: Updated
android/build.gradleandandroid/app/build.gradleto use Kotlin 1.9.22.buildscript { ext.kotlin_version = "1.9.22" }Set explicit JVM targets in Gradle files:
android { compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = '17' apiVersion = '1.9' languageVersion = '1.9' } }Forced specific androidx.work dependencies:
configurations.all { resolutionStrategy { force 'androidx.work:work-runtime:2.8.1' force 'androidx.work:work-runtime-ktx:2.8.1' force 'androidx.concurrent:concurrent-futures:1.1.0' } }Tried different versions of the
workmanagerplugin: Tested with versions 0.5.0, 0.5.1, and 0.5.2, but the issue persists.
Relevant Code:
Initialization in main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Workmanager().initialize(
callbackDispatcher,
isInDebugMode: true,
);
// ... rest of initialization
}
@pragma('vm:entry-point')
void callbackDispatcher() async {
Workmanager().executeTask((task, inputData) async {
switch (task) {
case WidgetService.WIDGET_UPDATE_TASK:
print('Processing widget update task');
return true;
default:
return false;
}
});
}
Question:
How can I resolve this build issue while keeping the workmanager functionality? The widget updates are crucial for my app's functionality on both platforms.
Any help or suggestions would be greatly appreciated!