1

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:

  1. Updated Kotlin version: Updated android/build.gradle and android/app/build.gradle to use Kotlin 1.9.22.

    buildscript {
        ext.kotlin_version = "1.9.22"
    }
    
  2. 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'
        }
    }
    
  3. 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'
        }
    }
    
  4. Tried different versions of the workmanager plugin: 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!

1 Answer 1

2

I can't say this will fix your issue, but because your question appeared when I was searching an answer for my own build issue with with workmanager, I'll post what I found.

There's currently an issue with the workmanager pub with the newer versions of flutter. People posted a workaround that relies on the repo directly that got my project building for now. We'll see when they update the pub. Hope this helps!

Credit to zhushenwudi on the github issue post.

workmanager:
    git:
      url: https://github.com/fluttercommunity/flutter_workmanager.git
      path: workmanager
      ref: main
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.