1

I'm creating an app using Xamarin.Forms . This app runs correctly on emulator (android version 7.1) in Visual Studio 2017. But gives "Parse Error : There was problem parsing the package." while installing it on my phone (Android version : 5.1). Can anyone please help in solving this issue ???? Thanks in advance !!!!

ToastService Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace XamService.Droid.Services
{
    [Service(Exported = true , Name = "XamService.ToastService")]
    class ToastService : Service
    {
        public override IBinder OnBind(Intent intent)
        {
            throw new NotImplementedException();
        }

        [return: GeneratedEnum]
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            Toast.MakeText(Android.App.Application.Context, "This is a toast from service !", ToastLength.Long).Show();
            return StartCommandResult.Sticky;
        }

    }
}

ServiceCaller class

using Android.App;
using Android.Content;
using XamService.Interfaces;
using XamService.Droid.Services;
using XamService.Droid;
using Xamarin.Forms;

[assembly:Dependency(typeof(ServiceCaller))]
namespace XamService.Droid
{
    class ServiceCaller : Activity, ICaller
    {
        public void serviceCaller()
        {
            Intent intent = new Intent(Forms.Context, typeof(ToastService));
            Forms.Context.StartService(intent);
        }
    }
}

AndoridManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          android:versionCode="1" 
          android:versionName="1.0" 
          package="com.companyname.XamService" 
          android:installLocation="auto">
    <uses-sdk android:minSdkVersion="15" />
    <application android:label="XamService.Android">
        <service android:name="ToastService" enabled="true"></service>
    </application>
</manifest>

enter image description here

enter image description here

Abhishek
  • 79
  • 10
  • Please read [this](https://techxoom.com/fix-parse-error-in-android-there-is-a-problem-parsing-the-package/) and [this](https://stackoverflow.com/questions/1492401/parse-error-there-is-a-problem-parsing-the-package-while-installing-android). – Robbit May 02 '18 at 01:58
  • Previously it did not have background services in android and worked fine. After adding background service in android, this error is coming... – Abhishek May 02 '18 at 02:10
  • ``, you added this manually?Try to delete the bin and obj folder, and delete the app on your phone, reinstall it. – Robbit May 02 '18 at 02:57
  • Yes manually. OK I'll try the steps mentioned. – Abhishek May 02 '18 at 04:22
  • @JoeLv-MSFT I tried, didn't work – Abhishek May 02 '18 at 15:10
  • Try use adb command to install the apk. Also, please refer to [this](https://stackoverflow.com/a/3268903/8632294). – Robbit May 09 '18 at 06:36
  • I was able to solve the issue. I removed tags from AndroidManifest.xml and just added [Service] above every service class. Thank you for all suggestions though !!! – Abhishek May 09 '18 at 10:37

0 Answers0