Skip to content

[background-http] App crashes due to IllegalArgumentException #318

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

Open
grigala opened this issue Aug 19, 2022 · 9 comments
Open

[background-http] App crashes due to IllegalArgumentException #318

grigala opened this issue Aug 19, 2022 · 9 comments

Comments

@grigala
Copy link
Contributor

grigala commented Aug 19, 2022

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 gotev/android-upload-service#510 createNotificationChannel() needs to be called explicitly.

@madmas
Copy link
Contributor

madmas commented Aug 25, 2022

Might be related to #274

@pap5508
Copy link

pap5508 commented Sep 1, 2022

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

@grigala
Copy link
Contributor Author

grigala commented Sep 1, 2022

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);
        }

@LaKing
Copy link

LaKing commented Nov 15, 2022

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

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

@LaKing
Copy link

LaKing commented Nov 15, 2022

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

@Maxeeezy
Copy link

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?

@pap5508
Copy link

pap5508 commented Nov 25, 2022

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

@chimmelb
Copy link
Contributor

chimmelb commented Nov 7, 2023

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)

@nielswitte
Copy link

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)

I am experiencing the same issue. Sometimes it throws the exception about a missing namespace when returning from the camera.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants