-
Notifications
You must be signed in to change notification settings - Fork 528
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
Android Service does not start if process name is specified in Service attribute #9132
Comments
I assume the version specified above is close enough, but here is the exact output from the dotnet workload list command: Welcome to .NET 8.0!SDK Version: 8.0.303 |
This issue has been verified using Visual Studio 17.11.0 Preview 3 (8.0.70 & 8.0.3). Can repro it. |
Any chance for a workaround here? If not I'll have to split my service out to a separate, native Java/Kotlin apk, which I'd really rather not do. |
I'm not sure we can support this. Running a service in a seperate process would require the runtime to be initialised I think, I'm not sure we have the hooks in place for that? @jonpryor am I mis remembering this? I seem to remember seperate processes for services was a no go at this time? |
@dellis1972, @jonpryor thank you for looking into this. Would you have any advice on how to move forward? Is my only option to create and install a separate apk for the service to run in? Thanks... |
Sorry to be a nuisance, @dellis1972 and @jonpryor, but getting an answer on this would help me tremendously in moving forward with my project. Thanks... |
@dellis1972: you're thinking of isolated processes, which we don't support:
"Normal" |
@jfichtner: it works for me? Start with MauiApp24.zip, and apply this patch: diff --git a/Platforms/Android/MainApplication.cs b/Platforms/Android/MainApplication.cs
index 0fee904..de5faf1 100644
--- a/Platforms/Android/MainApplication.cs
+++ b/Platforms/Android/MainApplication.cs
@@ -21,8 +21,14 @@ namespace MauiApp24
[Service(Process = ":test")]
public class TestService : Service
{
+ public TestService ()
+ {
+ Console.WriteLine ("# jonp: TestService is created!");
+ }
+
public override IBinder? OnBind(Intent? intent)
{
+ Console.WriteLine ($"# jonp: TestService.OnBind! intent={intent}");
return null;
}
@@ -33,6 +39,7 @@ namespace MauiApp24
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags startCommandFlags, int startId)
{
+ Console.WriteLine ($"# jonp: TestService.OnStartCommand! intent={intent} startCommandFlags={startCommandFlags} startId={startId}");
return StartCommandResult.Sticky;
}
} Start capturing adb logcat > log.txt & Build, install, run:
The first line is the initial launch of Later, we see Finally, we see the added Perhaps it's debugging this app which doesn't work as expected? (I have not tried using the debugger.) It certainly appears to work as expected for me… |
@jfichtner: I would not expect the debugger to work in this scenario, as if I recall correctly, the debugger only wants to deal with one process, and this setup involves two: the process with the Activity, and the process with the Service. Debugging multi-process scenarios is beyond my knowledge. |
@jonpryor Ah, I see! So, my test was flawed in that I was expecting the debugger to hit the breakpoint, but since the service is running in a different process the breakpoint won't be hit. I didn't even consider that, so thank you for taking the time! This does address my issue, because I only need to run in a separate process. However, there still seems to be an issue with specifying a process that does not start with a colon, as this results in a deployment error. |
@jfichtner I have created a service for the maui community toolkit. I use it in MediaElement. Here is an example scenario:
Here is link to repo with service: https://github.com/ne0rrmatrix/MauiOld/blob/Media3/src/CommunityToolkit.Maui.MediaElement/Services/MediaControlsService.android.cs I tested with
and my service worked fine. Maybe it is because I am using a foreground service? |
@ne0rrmatrix as I mentioned above, I realized that the service does work, it just doesn't attach the debugger. It still does NOT work if the process name doesn't start with a colon. |
Description
In a .NET 8 MAUI app, when I attempt to create an Android service that starts in a private process using the Service attribute, and specifying a process name with a colong as the first character as such:
[Service(Process = ":test")] public class TestService : Service
The service simply does not start when attempting to start by calling:
context.StartService(new Intent(context, typeof(TestService)));
In addition, if I remove the colon from the process string I get the following error when attempting to deploy the project:
ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install output: Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: Failed parse during installPackageLI: Failed to read manifest from /data/app/vmdl699026415.tmp/base.apk: com.android.server.pm.pkg.component.ParsedServiceImpl cannot be cast to java.lang.String]
Steps to Reproduce
Create a new .NET MAUI application from the template in VS2022 and add the following class to the MauiApplication file:
Then in the MainApplication constructor add:
TestService.start(this);
I deployed this to a Pixel 5 emulator for my testing.
When attempting to deploy and run this application, note the following:
Link to public reproduction project repository
No response
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: