android-upload-service: Question on crash message when closing the app: Unable to create service net.gotev.uploadservice.UploadService

I have implemented the background service successfully, it’s working as a charm. Thanks a lot for this library!

However, I noticed some behaviour: When I kill the application by swiping it off, I get this error message in logcat:

Unable to create service net.gotev.uploadservice.UploadService: java.lang.IllegalArgumentException: You have to set namespace to your app package name (context.packageName) in your Application subclass

and Android reports an app crash.

I have read in https://github.com/gotev/android-upload-service/issues/510 that this might be related to android:name not being set in AndroidManifest.xml, as also stated in the docs. However, I am developing a plugin for Unity, and Unity does not use a class that derives from Application.

ChatGPT recommended me to set the UnityPluginActivity instead because that is the main entry point for a Unity project. This did not work, because it does not inherit from Application. When I hinted it to this, it recommended to create a blank Application instead.

My questions here:

  • Is this a safe and valid approach?
  • Can it this be done in an Android library that will be imported into the actual application?
  • Which package name should I use? That of my library or that of the main Unity application?
  • Is there any other way to ensure that the library works as expected?

The error occurs only happens if I kill the app. Otherwise, everything works fine, even without the android:name prop. I have done all the initialization stuff in the Activity, using application as the context for UploadServiceConfig.initialize. This worked, but I do not know what class name this application keyword is actually referring to.

Thanks in advance for your support.

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

I just found out that it must be a problem with my WiFi right now. I tried it on the iPhone and had the same slow speeds. When I switched to a mobile network, things were much faster. Sorry for bothering.

Speaking about native apps, setting android:name value == yourApplicationSubclass in the manifest is necessary to register your application subclass and get it run by android on specific app lifecycle moments, one of which is onCreate, when the app gets instantiated and before the first activity is created. This is standard android practice.

As you have described, unity wrappers may differ, and you are experiencing the crash, so follow their guidance in this case.

From a library standpoint, problems you are facing are not due to the lib. Just init it in the best place advised by Unity folks, before starting the first upload. My docs are meant to guide integration on purely native apps.