I'm working on an application using Xamarin and MvvmCross framework. As I need to make the remote api call every x hours, I'm trying to implement JobScheduler
.
I started with adding this class:
using Android.App;
using Android.App.Job;
namespace CMKOS.Droid.Service
{
[Service(Name = "CMKOS.FibonacciJob", Permission = "android.permission.BIND_JOB_SERVICE")]
public class FibonacciJob : JobService
{
public override bool OnStartJob(JobParameters jobParams)
{
// Called by the operating system when starting the service.
// Start up a thread, do work on the thread.
return true;
}
public override bool OnStopJob(JobParameters jobParams)
{
// Called by Android when it has to terminate a running service.
return false; // Don't reschedule the job.
}
}
}
Here I get Deployment failed error with this log output:
/Library/Frameworks/Mono.framework/Versions/5.8.0/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2057,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "MvvmCross.Droid.Support.Design". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
/Library/Frameworks/Mono.framework/Versions/5.8.0/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2057,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error : Unexpected install output: pkg: /data/local/tmp/com.xxx.cmkos-Signed.apk
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error : Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error :
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error : at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess (System.String output, System.String packageName) [0x0013f] in /Users/builder/data/lanes/5809/22d97e15/source/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Internal/AdbOutputParsing.cs:337
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error : at Mono.AndroidTools.AndroidDevice+<>c__DisplayClass94_0.<InstallPackage>b__0 (System.Threading.Tasks.Task`1[TResult] t) [0x00016] in /Users/builder/data/lanes/5809/22d97e15/source/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/AndroidDevice.cs:746
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error : at System.Threading.Tasks.ContinuationTaskFromResultTask`1[TAntecedentResult].InnerInvoke () [0x00024] in <2722d81e5b26475cb5f475fea055f291>:0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets(479,2): error : at System.Threading.Tasks.Task.Execute () [0x00010] in /Users/builder/data/lanes/5533/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502
2 Warning(s)
1 Error(s)
When I remove the JobService
superclass, app deploys without any errors:
using Android.App;
namespace CMKOS.Droid.Service
{
[Service(Name = "CMKOS.FibonacciJob", Permission = "android.permission.BIND_JOB_SERVICE")]
public class FibonacciJob
{
//public override bool OnStartJob(JobParameters jobParams)
//{
// // Called by the operating system when starting the service.
// // Start up a thread, do work on the thread.
// return true;
//}
//public override bool OnStopJob(JobParameters jobParams)
//{
// // Called by Android when it has to terminate a running service.
// return false; // Don't reschedule the job.
//}
}
}
Do you have any idea why this is happening? I tried to put permission also to AndroidManifest
, but no luck.
This happens when the ServiceAttribute.Name
value doesn't match the C# namespace. Everything up to the name of the class must be in lowercase as well. Change your ServiceAttribute
to look like this:
[Service(Name = "cmkos.droid.service.FibonacciJob", Permission = "android.permission.BIND_JOB_SERVICE")]