Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Worker result FAILURE" on Android #3

Closed
webpn opened this issue Jun 12, 2018 · 17 comments
Closed

"Worker result FAILURE" on Android #3

webpn opened this issue Jun 12, 2018 · 17 comments
Labels
bug Something isn't working

Comments

@webpn
Copy link

webpn commented Jun 12, 2018

Plugin works like a breeze on iOS, but I get an error on Android.

This is what I get from the log:

I/flutter (27342): Download task is enqueued with id(a1fd47bc-d615-41ba-8eb9-65dc173bfafb)
D/SystemJobScheduler(27342): Scheduling work ID a1fd47bc-d615-41ba-8eb9-65dc173bfafb Job ID 19
D/GreedyScheduler(27342): Starting tracking for a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/SystemJobService(27342): onStartJob for a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/ConstraintTracker(27342): NetworkStateTracker: initial state = [ Connected=true Validated=true Metered=false NotRoaming=true ]
D/NetworkStateTracker(27342): Registering network callback
D/WorkConstraintsTracker(27342): Constraints met for a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/GreedyScheduler(27342): Constraints met: Scheduling work ID a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/WorkConstraintsTracker(27342): Constraints met for a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/GreedyScheduler(27342): Constraints met: Scheduling work ID a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/Processor(27342): Processor: processing a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/Processor(27342): Work a1fd47bc-d615-41ba-8eb9-65dc173bfafb is already enqueued for processing
D/Processor(27342): Work a1fd47bc-d615-41ba-8eb9-65dc173bfafb is already enqueued for processing
D/NetworkStateTracker(27342): Network capabilities changed: [ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&FOREGROUND LinkUpBandwidth>=1048576Kbps LinkDnBandwidth>=1048576Kbps SignalStrength: -50]
D/WorkerWrapper(27342): Worker result FAILURE for a1fd47bc-d615-41ba-8eb9-65dc173bfafb
D/Processor(27342): Processor a1fd47bc-d615-41ba-8eb9-65dc173bfafb executed; isSuccessful = false, reschedule = false
D/SystemJobService(27342): a1fd47bc-d615-41ba-8eb9-65dc173bfafb executed on JobScheduler
I/zygote64(27342): Do partial code cache collection, code=61KB, data=47KB
I/zygote64(27342): After code cache collection, code=61KB, data=47KB
I/zygote64(27342): Increasing code cache capacity to 256KB

This is my code:

String taskId = await FlutterDownloader.enqueue(url: link, savedDir: path,);

I know nothing about Android Studio or how to debug Android Apps, so I really don't know how where to start to debug this issue.

Thanks

@webpn
Copy link
Author

webpn commented Jun 12, 2018

I tried using different urls, both on HTTP and on HTTPS, but I get the same error.

@hnvn
Copy link
Member

hnvn commented Jun 13, 2018

I can't reproduce your problem. If you don't mind, give me the source code to reproduce it.

@hnvn hnvn added the bug Something isn't working label Jun 13, 2018
@cbenhagen
Copy link

I see the same issue when I run the example from this repository:

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
I/FlutterActivityDelegate(12202): onResume setting current activity to this
Syncing files to device Android SDK built for x86...
D/        (12202): HostConnection::get() New Host Connection established 0xe7398880, tid 12223
D/EGL_emulation(12202): eglMakeCurrent: 0xe70833c0: ver 3 0 (tinfo 0xe7383340)
I/flutter (12202): Download task (78e95445-4759-4cfa-ade6-3dea7c66ae32) is in status (DownloadTaskStatus(1)) and process (0)
I/flutter (12202): Download task is enqueued with id(78e95445-4759-4cfa-ade6-3dea7c66ae32)
D/SystemJobScheduler(12202): Scheduling work ID 78e95445-4759-4cfa-ade6-3dea7c66ae32 Job ID 71
D/GreedyScheduler(12202): Starting tracking for 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/SystemJobService(12202): onStartJob for 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/ConstraintTracker(12202): NetworkStateTracker: initial state = [ Connected=true Validated=true Metered=false NotRoaming=true ]
D/NetworkStateTracker(12202): Registering network callback
D/WorkConstraintsTracker(12202): Constraints met for 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/GreedyScheduler(12202): Constraints met: Scheduling work ID 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/WorkConstraintsTracker(12202): Constraints met for 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/GreedyScheduler(12202): Constraints met: Scheduling work ID 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/Processor(12202): Processor: processing 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/Processor(12202): Work 78e95445-4759-4cfa-ade6-3dea7c66ae32 is already enqueued for processing
D/Processor(12202): Work 78e95445-4759-4cfa-ade6-3dea7c66ae32 is already enqueued for processing
D/NetworkStateTracker(12202): Network capabilities changed: [ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&FOREGROUND LinkUpBandwidth>=1048576Kbps LinkDnBandwidth>=1048576Kbps SignalStrength: -50]
D/WorkerWrapper(12202): Worker result FAILURE for 78e95445-4759-4cfa-ade6-3dea7c66ae32
D/Processor(12202): Processor 78e95445-4759-4cfa-ade6-3dea7c66ae32 executed; isSuccessful = false, reschedule = false
D/SystemJobService(12202): 78e95445-4759-4cfa-ade6-3dea7c66ae32 executed on JobScheduler

On the beta channel:

[✓] Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.5 17F77, locale de-CH)
    • Flutter version 0.4.4 at /Users/ben/flutter
    • Framework revision f9bb4289e9 (5 weeks ago), 2018-05-11 21:44:54 -0700
    • Engine revision 06afdfe54e
    • Dart version 2.0.0-dev.54.0.flutter-46ab040e58

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/ben/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4, Build version 9F1027a
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 25.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)

• No issues found!

And dev:

lutter doctor -v
[✓] Flutter (Channel dev, v0.5.4, on Mac OS X 10.13.5 17F77, locale de-CH)
    • Flutter version 0.5.4 at /Users/ben/flutter
    • Framework revision 3019ad976d (2 days ago), 2018-06-11 11:31:25 -0700
    • Engine revision d33bbff470
    • Dart version 2.0.0-dev.60.0.flutter-a5e41681e5

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/ben/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4, Build version 9F1027a
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 25.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)

• No issues found!

@webpn
Copy link
Author

webpn commented Jun 13, 2018

Sure, I'll publish my repo soon (probably in next 12 hours): maybe the error is caused by some conflict with other installed packages.

@webpn
Copy link
Author

webpn commented Jun 13, 2018

Here it is: https://github.com/webpn/demo_downloader

I just picked the interesting part from my app and placed it into a fresh install of Flutter.

If it could be helpful, this is the output from Flutter Doctor:

[✓] Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.5 17F77, locale it-IT)
    • Flutter version 0.4.4 at ~/dev/flutter
    • Framework revision f9bb4289e9 (5 weeks ago), 2018-05-11 21:44:54 -0700
    • Engine revision 06afdfe54e
    • Dart version 2.0.0-dev.54.0.flutter-46ab040e58

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.0)
    • Android SDK at ~/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.0
    • ANDROID_HOME = ~/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4, Build version 9F1027a
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 25.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

@hnvn
Copy link
Member

hnvn commented Jun 14, 2018

I try your code and it works. btw, what device do you test and Android version?

@hnvn
Copy link
Member

hnvn commented Jun 14, 2018

I can reproduce this matter on Android Simulator (running Android 28). I am working on it.

@hnvn
Copy link
Member

hnvn commented Jun 14, 2018

There's a problem with WorkManager library (still in alpha), it causes this plugin failure on Android 26 and above. I need to wait for the next version of WorkManager.

@webpn
Copy link
Author

webpn commented Jun 14, 2018

I tested that code directly on my phone, which runs on Android 8.0.0 (= API level 26).

@hnvn
Copy link
Member

hnvn commented Jun 14, 2018

There's a significant change of background task policy from API 26. I think it causes our problem. I just created an issue for WorkManager, it's a new project of Google, so it would be updated soon.

@hnvn
Copy link
Member

hnvn commented Jun 14, 2018

There's a mature library called JobIntentService can address our problem, I think I will consider switching to it

@hnvn
Copy link
Member

hnvn commented Jun 15, 2018

I got it worked. It's just my stupid mistake when I config NotificationChannel (not the problem of WorkManager library). I've just published v.0.0.4. Let's check it out.

@hnvn hnvn closed this as completed Jun 15, 2018
@webpn
Copy link
Author

webpn commented Jun 15, 2018

Yay, it works perfectly!

Feature suggestion: new parameter to specify how many concurrent download should be running.

@hnvn
Copy link
Member

hnvn commented Jun 16, 2018

I can set the max concurrent download task on iOS side (in fact, I set it 5 now) but I don't see anything like that in WorkManager on Android side. I will bring up this feature when I can deal with Android side

@Joao-Filh0
Copy link

I have this problem , can you help me ?

java.lang.NullPointerException: uri
W/System.err( 9348): at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:133)
W/System.err( 9348): at android.content.ContentResolver.query(ContentResolver.java:918)
W/System.err( 9348): at android.content.ContentResolver.query(ContentResolver.java:880)
W/System.err( 9348): at android.content.ContentResolver.query(ContentResolver.java:836)
W/System.err( 9348): at vn.hunghd.flutterdownloader.DownloadWorker.getMediaStoreEntryPathApi29(DownloadWorker.java:531)
W/System.err( 9348): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:394)
W/System.err( 9348): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:235)
W/System.err( 9348): at androidx.work.Worker$1.run(Worker.java:86)
W/System.err( 9348): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err( 9348): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err( 9348): at java.lang.Thread.run(Thread.java:919)
I/WM-WorkerWrapper( 9348): Worker result FAILURE for Work [ id=9b39dcf7-121d-4c59-a740-68496528c170, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]

@ramonpaolo
Copy link

ramonpaolo commented Jun 25, 2022

I have the same problem today

With: flutter_downloader: ^1.7.0+1

@ElsayedDev
Copy link

ElsayedDev commented Dec 10, 2022

Make sure you added this permissions in AndroidManifest.xml


    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

In main function add FlutterDownloader.registerCallback(DownloadClass.callback); ( it is take static callback )

as mentioned in https://stackoverflow.com/a/72889016/11989529

abstract class DownloadClass {
  static void callback(String id, DownloadTaskStatus status, int progress) {
    debugPrint("Download Status:: $status");
    debugPrint("Download Progress:: $progress");
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await FlutterDownloader.initialize(debug: true);

  FlutterDownloader.registerCallback(DownloadClass.callback);

  runApp(const MyApp());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants