Repository navigation
Description
Android framework version
net11.0-android
Affected platform version
Microsoft.Android.Sdk 37.2.31 / .NET SDK 11.0.100. Also reproduced with a published 37.2.0-rc.2.84 app. ARM64, Release, PublishAot=true.
Description
The attached app schedules one periodic JobService. The job works on a normal cold start. When Android starts the process for full backup, it uses android.app.Application and skips content providers, including NativeAotRuntimeProvider. After Android unbinds the backup agent, JobScheduler can deliver the job to that same process. The generated service class calls mono.android.Runtime.registerNatives from its static initializer and throws UnsatisfiedLinkError before managed OnStartJob runs.
I would expect the job to remain scheduled and run in a process with normal application initialization. Could the SDK detect this case before the generated service calls JNI and defer the job? I reproduced it with the .NET 11 GA workload. The sample uses the default backup agent.
A related Xamarin report observed Runtime.register throwing while Android was creating a custom BackupAgent. In this sample the agent has already been unbound when Android creates the service. #2292 (comment)
I used AI to help investigate this crash and draft this report.
Steps to Reproduce
- Unzip jobservice-repro.zip. Use an API 33 ARM64 Google APIs userdebug emulator, a JDK, .NET 11 with the Android workload, Android SDK platform android-37.2 and build-tools 37.0.0.
- Set ANDROID_HOME to the SDK path. Run bash reproduce.sh emulator-5554, substituting the emulator serial. The script builds the sample and schedules job 123.
- The harness kills only the sample process while retaining the job. It calls ActivityManager.bindBackupAgent in full-backup mode, waits for the process, and unbinds without requesting any backup data. It then runs cmd jobscheduler run -f example.jobstartup 123.
- Inspect the crash buffer for the restricted PID. The service initializer throws before managed OnStartJob runs. A normal service-initiated process starts its provider and executes the same job.
Did you find any workaround?
In apps that normally use a custom Application, I registered a Java JobService as the entry point. When getApplication().getClass() == android.app.Application.class, it calls jobFinished(parameters, true) and returns true from onStartJob. In a normal process it dispatches to the managed implementation. I verified that the restricted process survived, JobScheduler retained the job with backoff, and managed work completed in a fresh normal process. This check relies on the app having a custom Application in normal launches.
Relevant log output
java.lang.UnsatisfiedLinkError: No implementation found for void mono.android.Runtime.registerNatives(java.lang.Class)
at mono.android.Runtime.registerNatives(Native Method)
at scrc647254390c527c84fa.PeriodicTask.<clinit>
at java.lang.Class.newInstance
at android.app.AppComponentFactory.instantiateService
at android.app.ActivityThread.handleCreateService
Activity
simonrozsival commentedon Nov 19, 2026
Thanks for the bugreport. I'm looking into it.
simonrozsival commentedon Nov 19, 2026
Thanks for the detailed report, @tipa. I was able to reproduce the crash and trace it to how Android starts the process—not to NativeAOT or the typemap.
When Android starts an app for full backup or restore, it can use a restricted startup mode: it creates the base
android.app.Applicationand skips installing the app’s content providers. .NET for Android normally initializes the runtime through a content provider, so in that process the runtime—and the native registration methods used by generated Java wrappers—has not been initialized.If Android later reuses that process for the scheduled job, loading the generated
JobServicewrapper fails in its static initializer, before the managed service code runs. Thejava.lang.Classin the exception is the parameter type to the native registration method; the class being registered is stillPeriodicTask.I reproduced this on an Android 15/API 35 ARM64 emulator with .NET 11 RC using NativeAOT and CoreCLR with the legacy typemap. CoreCLR’s legacy wrapper calls
Runtime.register; NativeAOT and the trimmable typemap callRuntime.registerNatives. Both fail when the runtime hasn’t been initialized. Your report confirms the NativeAOT case on the .NET 11 GA workload.The backup results depend on the kind of agent and whether the process is cold:
This appears to be an older limitation of the provider-based startup model, rather than a NativeAOT regression. Android’s source shows the restricted startup path skipping providers as far back as Android 5. There is also a 2018 comment on #2292 describing
Runtime.registerfailing while Android creates a custom backup agent. That is strong evidence of the same kind of startup failure, though the old report does not include enough detail to confirm identical conditions. Other reports such as #4557 have similar service-initializer errors, but don’t establish restricted backup as their cause.Your Java-only
JobServiceshim is a reasonable workaround for the reported job case: it detects the restricted process and defers the job before the generated managed wrapper is loaded. A general SDK fix would need to intercept startup before that wrapper is initialized, and account for existing application/component factories and retry behavior. I haven’t validated a general SDK fix.