plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[background-http] App crashes due to IllegalArgumentException

Open grigala opened this issue 2 years ago • 8 comments

Latest @nativescript/background-http crashes some Android devices with You have to set namespace to your app package name (context.packageName) in your Application subclass:

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:4641)

Full trace from Google Play Console:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleCreateService (ActivityThread.java:4655)
  at android.app.ActivityThread.access$2800 (ActivityThread.java:251)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2319)
  at android.os.Handler.dispatchMessage (Handler.java:110)
  at android.os.Looper.loop (Looper.java:219)
  at android.app.ActivityThread.main (ActivityThread.java:8393)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:513)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1055)
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:4641)

Calling init() from the main.ts does not help this particular problem, because error occurs while having this in my main.ts:

import { init } from "@nativescript/background-http";

init();

According to https://github.com/gotev/android-upload-service/issues/510 createNotificationChannel() needs to be called explicitly.

grigala avatar Aug 19 '22 11:08 grigala

Might be related to #274

madmas avatar Aug 25 '22 12:08 madmas

@grigala : Have you found a solution for this? I am also stuck with the same problem

pap5508 avatar Sep 01 '22 08:09 pap5508

Hi @pap5508, nothing that's 100% tested so far, but you can give it a try and do this before you call/construct bghttp session:

 if (android.os.Build.VERSION.SDK_INT >= 26) {
            const channel = new android.app.NotificationChannel(
                "NotificationChannel", 
                "My App", 
                android.app.NotificationManager.IMPORTANCE_HIGH // adjust to your requirement
            );
            const manager = Utils.android
                .getApplicationContext()
                .getSystemService(android.content.Context.NOTIFICATION_SERVICE) as android.app.NotificationManager;

            manager.createNotificationChannel(channel);
        }

grigala avatar Sep 01 '22 09:09 grigala

if (android.os.Build.VERSION.SDK_INT >= 26) { ...

I can't get it working with this. Get the same error.

LaKing avatar Nov 15 '22 05:11 LaKing

The init() function is new, .. after adding it I have this issue resolved for now.

LaKing avatar Nov 15 '22 05:11 LaKing

I face the same issue. However, the init() calling before uploading multipart still gives me the same error... Where are you calling the init? main.ts still?

Maxeeezy avatar Nov 25 '22 11:11 Maxeeezy

@Maxeeezy : Yes, I have added in main.ts and working fine.

pap5508 avatar Nov 25 '22 13:11 pap5508

I run into this issue as well on Android. Not every upload (we use init()) but some fail.

Caused by java.lang.IllegalArgumentException: You have to set namespace to your app package name (context.packageName) in your Application subclass
       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)

(extra info but theory: I think it's related to coming back from a Camera activity and somehow that namespace is not ready. I called init() in appResume (should be idempotent if already initialized) but that doesn't seem to fix it completely)

chimmelb avatar Nov 07 '23 15:11 chimmelb