fluttercommunity / flutter_workmanager

A Flutter plugin which allows you to execute code in the background on Android and iOS.
825 stars 247 forks source link

🐞Type 'WorkmanagerPlugin' has no member 'registerBGProcessingTask' and Type 'WorkmanagerPlugin' has no member 'registerPeriodicTask' #551

Open Brechard opened 2 months ago

Brechard commented 2 months ago

Version

Technology Version
Workmanager version 0.5.2
Xcode version 15.3
Swift version 5.10
iOS deployment target 12

Describe the error

I was following the setup for iOs and when reaching the "You MUST amend your AppDelegate.swift and Info.plist file to register your task ID." I receive those errors in Xcode.

I have cloned this repo and the same errors show on the example (on the flutter side there are 4 errors like: error: The method 'registerProcessingTask' isn't defined for the type 'Workmanager'. (undefined_method at [workmanager_example] lib/main.dart:266)

Output of flutter doctor -v

[βœ“] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-US) β€’ Flutter version 3.19.6 on channel stable at ~/software/flutter β€’ Upstream repository https://github.com/flutter/flutter.git β€’ Framework revision 54e66469a9 (7 days ago), 2024-04-17 13:08:03 -0700 β€’ Engine revision c4cd48e186 β€’ Dart version 3.3.4 β€’ DevTools version 2.31.1

[βœ“] Android toolchain - develop for Android devices (Android SDK version 34.0.0) β€’ Android SDK at ~/Library/Android/sdk β€’ Platform android-34, build-tools 34.0.0 β€’ Java binary at: ~/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 15.3) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Build 15E204a β€’ CocoaPods version 1.15.2

[βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 2023.2) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[βœ“] Android Studio (version 2023.3) β€’ Android Studio at ~/Applications/Android Studio.app/Contents β€’ Flutter plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[βœ“] IntelliJ IDEA Ultimate Edition (version 2024.1.1) β€’ IntelliJ at /Applications/IntelliJ IDEA.app β€’ Flutter plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart

[βœ“] VS Code (version 1.88.0) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.84.0

[βœ“] Connected device (4 available) β€’ Pixel 8 (mobile) β€’ 39011FDJH007KM β€’ android-arm64 β€’ Android 14 (API 34) β€’ iPhone 15 Pro (mobile) β€’ 195714BD-9F6E-47A9-9886-313A3A97FC68 β€’ ios β€’ com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator) β€’ macOS (desktop) β€’ macos β€’ darwin-arm64 β€’ macOS 14.4.1 23E224 darwin-arm64 β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 124.0.6367.62

[βœ“] Network resources β€’ All expected network resources are available.

Cmk427 commented 2 months ago

You may try to change the branch of the package in pubspec.yaml file:

  workmanager:
    git:
      url: https://github.com/absar/flutter_workmanager.git
      ref: ios-bg-tasks-enh-final

It may help you to solve your issue at this moment.

joonne commented 1 month ago

The above solution seems to work, I'm now able to build the app and triggering the background task from the debugger works. Could we get a comment whether this is the "correct" solution for making this plugin work on iOS at the moment?

nk4n01 commented 1 month ago

I got the same error !!

razumeiko commented 1 month ago

Don't you think that it's weird? The official git link is https://github.com/fluttercommunity/flutter_workmanager but you are pulling code from https://github.com/absar/flutter_workmanager.git who knows what he could code there.

joonne commented 1 month ago

I could have elaborated a bit, those changes from https://github.com/absar/flutter_workmanager.git are actually in main already and waiting to be released: https://github.com/fluttercommunity/flutter_workmanager/commit/b783000c18f6e066f3d81d5ecc352f3ce61860f6 πŸ‘

(or that is how I understood the situation)

dario-digregorio commented 1 month ago

I spend too much time figuring out why the described setup is not working with my project until I realized that the link to the iOS Setup brings you to the GitHub Repo, has a different version than the one that is published on pub.dev πŸ₯² So for others that are struggling use the right version in your pubspec.yml and read the Readme's from that commit b783000.

Pubspec

  workmanager:
    git:
      url: https://github.com/fluttercommunity/flutter_workmanager.git
      ref: b783000
Kurokirisu commented 1 month ago

Pubspec

  workmanager:
    git:
      url: https://github.com/fluttercommunity/flutter_workmanager.git
      ref: b783000

I am now using this version instead of the 0.5.2 version and at first it worked fine, but now I get an error on Android:

  • What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'.

    A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class androidx.work.OneTimeWorkRequestKt found in modules work-runtime-2.8.1-runtime (androidx.work:work-runtime:2.8.1) and work-runtime-ktx-2.7.0-runtime (androidx.work:work-runtime-ktx:2.7.0) Duplicate class androidx.work.PeriodicWorkRequestKt found in modules work-runtime-2.8.1-runtime (androidx.work:work-runtime:2.8.1) and work-runtime-ktx-2.7.0-runtime (androidx.work:work-runtime-ktx:2.7.0)

I really need the periodic tasks to work on iOS, so I hope someone can help me with this since they don't work in the 0.5.2 version.

ghufrankhan commented 1 month ago

Pubspec

  workmanager:
    git:
      url: https://github.com/fluttercommunity/flutter_workmanager.git
      ref: b783000

I am now using this version instead of the 0.5.2 version and at first it worked fine, but now I get an error on Android:

  • What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class androidx.work.OneTimeWorkRequestKt found in modules work-runtime-2.8.1-runtime (androidx.work:work-runtime:2.8.1) and work-runtime-ktx-2.7.0-runtime (androidx.work:work-runtime-ktx:2.7.0) Duplicate class androidx.work.PeriodicWorkRequestKt found in modules work-runtime-2.8.1-runtime (androidx.work:work-runtime:2.8.1) and work-runtime-ktx-2.7.0-runtime (androidx.work:work-runtime-ktx:2.7.0)

I really need the periodic tasks to work on iOS, so I hope someone can help me with this since they don't work in the 0.5.2 version.

Hi, try adding this line inside the dependencies array found in /android/app/build.gradle:

implementation("androidx.work:work-runtime-ktx:2.8.1")

Wegi commented 1 week ago

Anything to help this fixed version being released on pub.dev?