plugins icon indicating copy to clipboard operation
plugins copied to clipboard

@nativescript/background-http high number of crashes

Open nikoTM opened this issue 2 years ago • 7 comments

I am seeing a lot of crashes with java.lang.IllegalArgumentException when calling net.gotev.uploadservice.UploadServiceConfig.getNamespace

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleCreateService (ActivityThread.java:4673)
  at android.app.ActivityThread.access$1700 (ActivityThread.java:301)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2196)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:246)
  at android.app.ActivityThread.main (ActivityThread.java:8653)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)
Caused by: java.lang.IllegalArgumentException: 
  at net.gotev.uploadservice.UploadServiceConfig.getNamespace (UploadServiceConfig.kt:74)
  at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationAction (UploadServiceConfig.kt:234)
  at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationActionIntentFilter (UploadServiceConfig.kt:248)
  at net.gotev.uploadservice.observer.request.NotificationActionsObserver.register (NotificationActionsObserver.kt:31)
  at net.gotev.uploadservice.UploadService.onCreate (UploadService.kt:194)
  at android.app.ActivityThread.handleCreateService (ActivityThread.java:4661)

Other people seem to be having this issue as well (https://github.com/Vydia/react-native-background-upload/issues/288), the proposed solution is to use net.gotev:uploadservice-okhttp:4.7.0, which background-http already uses. There are some mentions in other threads that it might be due to not creating a notification channel which is supposed to happen here https://github.com/NativeScript/plugins/blob/ca9e56ae814c670f9c603157a3fe7eb70c9bbbea/packages/background-http/index.android.ts#L8

But I suspect it's not being called reliably since it's tied to application launch. @triniwiz does it need to be strictly called on launch? Is it okay to check didInit when creating a session and if it hasn't initialised, try to do so?

nikoTM avatar May 19 '22 12:05 nikoTM

Yeah just installed the package and getting the same error:

Execution failed for task ':app:processDebugMainManifest'. Manifest merger failed : uses-sdk:minSdkVersion 17 cannot be smaller than version 21 declared in library [net.gotev:uploadservice:4.7.0] /home/bernard/.gradle/caches/transforms-3/aabb9fd1a360dfd19fa3dd8d0f24e04f/transformed/jetified-uploadservice-4.7.0/AndroidManifest.xml as the library might be using APIs not available in 17 Suggestion: use a compatible library with a minSdk of at most 17, or increase this project's minSdk version to at least 21, or use tools:overrideLibrary="net.gotev.uploadservice" to force usage (may lead to runtime failures)

even if i explicitly call the init function in app.js import { init } from '@nativescript/background-http'; init();

Bernardmyburgh5 avatar May 24 '22 10:05 Bernardmyburgh5

Hi @Bernardmyburgh5 , this is not the same issue, you can bump your minSdkVersion to 21, in your app.gradle (App_Resources/Android/app.gradle) to get proper compatibility. The error is pretty descriptive.

nikoTM avatar May 24 '22 10:05 nikoTM

@nikoTM Thank you so much, that did fix my issue, and you are 100% right, the error is pretty descriptive, its more my knowledge of native script and native apps that is lacking. thanks for help, really appreciate it.

Bernardmyburgh5 avatar May 24 '22 11:05 Bernardmyburgh5

@nikoTM it has to be called before the Application.start (usually hidden on none core flavours) is called this can work if you add it to the top of your app.ts/app.js/main.ts

triniwiz avatar May 31 '22 13:05 triniwiz

@triniwiz I am doing that, but I still see crashes related as seen above, so I thought it would be possible to mitigate with ensuring it was called later on, but if it needs to be called before the app is started, I guess that's not possible. I will see if I can find a workaround.

nikoTM avatar May 31 '22 14:05 nikoTM

Which flavor are you using ?

triniwiz avatar May 31 '22 14:05 triniwiz

@triniwiz typescript/angular, if I understood the question correctly.

nikoTM avatar May 31 '22 14:05 nikoTM