1
votes

I'm recieving the above error when deploying my Xamarin Android application using Visual Studio in debug mode, the compile process completes fine but I can't deploy.

The app runs fine in Android 8.1.0 but not in any other lower version.

Error:

>Project "Empresa1.SMPay.Target.Droid.csproj" (Install target(s)):
>C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\zipalign.exe 4 "E:\HenkoTI\Empresa1\SMPay\src\mpay\app\Empresa1.SMPay.Target.Droid\obj\Debug\android\bin\br.com.henkoti.empresaum.smpay.apk" "bin\Debug\\br.com.henkoti.empresaum.smpay-Signed.apk" 
>C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\apksigner.BAT sign --ks "C:\Users\rodri\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 18 --max-sdk-version 27  bin\Debug\br.com.henkoti.empresaum.smpay-Signed.apk 
>Unexpected install output:     pkg: /data/local/tmp/br.com.henkoti.empresaum.smpay-Signed.apk
>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
>
>   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
>   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
>   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
>   at System.Threading.Tasks.Task.Execute()
>Done building project "Empresa1.SMPay.Target.Droid.csproj".
>Build succeeded.
>Unexpected install output:     pkg: /data/local/tmp/br.com.henkoti.empresaum.smpay-Signed.apk
>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
>
>   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
>   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
>   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
>   at System.Threading.Tasks.Task.Execute()

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.henkoti.empresaum.smpay" android:installLocation="auto" android:versionName="20181108.0" android:versionCode="4">
  <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.NFC" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
  <uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
  <application android:icon="@drawable/ic_launcher" android:theme="@style/MainTheme" android:label="SIGO" android:allowBackup="true" android:fullBackupContent="@xml/my_backup_rules">
    <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
    </provider>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
  </application>
</manifest>

Compiled AndroidManifest - Obj Folder

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.henkoti.empresaum.smpay" android:installLocation="auto" android:versionName="20181108.0" android:versionCode="4">
  <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.NFC" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
  <uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-feature android:name="android.hardware.camera" android:required="false" />
  <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
  <uses-feature android:name="android.hardware.location.gps" />
  <uses-feature android:name="android.hardware.location.network" />
  <application android:icon="@drawable/ic_launcher" android:theme="@style/MainTheme" android:label="SIGO" android:allowBackup="true" android:fullBackupContent="@xml/my_backup_rules" android:name="md5eaa617bc1882abd453813d82db97fb16.MainApplication" android:debuggable="true">
    <provider android:name="android.support.v4.content.FileProvider" android:authorities="br.com.henkoti.empresaum.smpay.fileprovider" android:exported="false" android:grantUriPermissions="true">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
    </provider>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
    <service android:enabled="true" android:exported="true" android:name="Empresa1.SMPay.HCECardService" android:permission="android.permission.BIND_NFC_SERVICE">
      <meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/aid_list" />
      <intent-filter>
        <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </service>
    <activity android:configChanges="orientation|screenSize" android:launchMode="standard" android:screenOrientation="portrait" android:theme="@style/MainTheme" android:name="md5eaa617bc1882abd453813d82db97fb16.MainActivity" />
    <activity android:icon="@drawable/ic_launcher" android:label="SIGO" android:noHistory="true" android:screenOrientation="portrait" android:theme="@style/SplashTheme" android:name="md5eaa617bc1882abd453813d82db97fb16.SplashActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <receiver android:enabled="true" android:label="Connectivity Plugin Broadcast Receiver" android:name="md592d74be4bac08a7af63848ae15d2f86e.ConnectivityChangeBroadcastReceiver" />
    <activity android:configChanges="orientation|screenSize" android:name="md5cf4be63b82b35b5ba951617c70f88a94.FilePickerActivity" />
    <activity android:configChanges="orientation|screenSize" android:name="md591f613f6733d8b6e91e929a922515c0e.MediaPickerActivity" />
    <receiver android:enabled="true" android:exported="false" android:name="md5b60ffeb829f638581ab2bb9b1a7f4f3f.PowerSaveModeBroadcastReceiver" />
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="br.com.henkoti.empresaum.smpay.mono.MonoRuntimeProvider.__mono_init__" />
    <!--suppress ExportedReceiver-->
    <receiver android:name="mono.android.Seppuku">
      <intent-filter>
        <action android:name="mono.android.intent.action.SEPPUKU" />
        <category android:name="mono.android.intent.category.SEPPUKU.br.com.henkoti.empresaum.smpay" />
      </intent-filter>
    </receiver>
    <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@style/com_facebook_activity_theme" />
    <activity android:name="com.facebook.CustomTabMainActivity" />
    <!--
         The initialization ContentProvider will call FacebookSdk.sdkInitialize automatically
         with the application context. This config is merged in with the host app's manifest,
         but there can only be one provider with the same authority activated at any given
         point; so if the end user has two or more different apps that use Facebook SDK, only the
         first one will be able to use the provider. To work around this problem, we use the
         following placeholder in the authority to identify each host application as if it was
         a completely different provider.
        -->
    <provider android:name="com.facebook.internal.FacebookInitProvider" android:authorities="br.com.henkoti.empresaum.smpay.FacebookInitProvider" android:exported="false" />
    <activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:excludeFromRecents="true" android:exported="false" />
    <!--Service handling Google Sign-In user revocation. For apps that do not integrate with
            Google Sign-In, this service will never be started.-->
    <service android:name="com.google.android.gms.auth.api.signin.RevocationBoundService" android:exported="true" android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
    <activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  </application>
</manifest>

SplashActivity

    using Android.OS;
    using Android.App;
    using Android.Content.PM;

    namespace Empresa1.SMPay.Target.Droid
    {
        [Activity(Label = "SIGO",
                  Icon = "@drawable/ic_launcher",
                  Theme = "@style/SplashTheme",
                  MainLauncher = true,
                  NoHistory = true,
                  ScreenOrientation = ScreenOrientation.Portrait)]    
        public class SplashActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
                this.StartActivity(typeof(MainActivity));
            }
        }
    }

MainActivity

    using System.Net;

    using Android.App;
    using Android.OS;
    using Android.Content;
    using Android.Content.PM;

    using Xamarin.Forms;
    using Xamarin.Facebook;
    using Plugin.Toasts;
    using Plugin.Permissions;
    using Acr.UserDialogs;
    using Autofac;

    using Empresa1.SMPay.Application;
    using Empresa1.SMPay.Application.IoC;
    using Empresa1.SMPay.Target.Droid.Services;
    using Empresa1.SMPay.Infra.Platform.Services;
    using Android.Gms.Auth.Api;
    using InteractiveAlert;
    using Xfx;
    using FFImageLoading.Forms.Droid;

    namespace Empresa1.SMPay.Target.Droid
    {
        [Activity(Theme = "@style/MainTheme",
                    LaunchMode = LaunchMode.Multiple,
                    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
                    ScreenOrientation = ScreenOrientation.Portrait)]
        public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource = Resource.Layout.Toolbar;

                base.OnCreate(bundle);

                // Facebook
                FacebookSdk.SdkInitialize(this.ApplicationContext);

                global::Xamarin.Forms.Forms.Init(this, bundle);

                // Calendar
                XamForms.Controls.Droid.Calendar.Init();

                // SSL
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

                // Permissions
                Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);

                // Toast
                DependencyService.Register<ToastNotification>();
                ToastNotification.Init(this);

                // Dialogs
                UserDialogs.Init(() => (Activity)Forms.Context);
                InteractiveAlerts.Init(() => this);

                // XfxControls
                XfxControls.Init();

                // FFImageLoading
                CachedImageRenderer.Init(true);            

                LoadApplication(new Empresa1.SMPay.Application.App(new Setup(this.ApplicationContext, this, TelephonyService)));            
            }

            protected override void OnStart()
            {
                base.OnStart();
            }

            protected override void OnResume()
            {
                base.OnResume();
            }

            protected override void OnPause()
            {
                base.OnPause();
            }

            protected override void OnStop()
            {
                base.OnStop();
            }

            public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
            {
                PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
                //base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            }

            protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
            {
                base.OnActivityResult(requestCode, resultCode, data);

                if (App.FacebookSinging)
                {
                    // facebook auth
                    var facebookService = IoCContainer.Container.Resolve<IFacebookService>();
                    if (facebookService != null)
                    {
                        (facebookService as DroidFacebookService)._callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
                    }
                }
                else if (App.GoogleSinging)
                {
                    // google auth
                    if (requestCode == 1)
                    {
                        var result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                        DroidGoogleService.Instance.OnAuthCompleted(result); // TODO
                    }
                }
            }
        }
    }

Anyone here knows, what do i need to do?

I took some screenshots to add here:

enter image description here enter image description here enter image description here

1
You should look in the obj folder for the generated AndroidManifest instead. As the one in properties is not the full. - Cheesebaron
Thanks, I added the compiled AndroidManifest in the question text. - Luis Rodrigues
Could it be the android.hardware.nfc.hce requirement? Can you try to set it to required false? - Cheesebaron
@Cheesebaron din't work, same problem =[ - Luis Rodrigues
logcat from the device will probably reveal more - Cheesebaron

1 Answers

2
votes

Finally I was able to solve the problem, the solution was to change the prefix name of the HCECardService to lowecase.

Before: Empresa1.SMPay.HCECardService

After: empresa1.smpay.HCECardService

[Service(Exported = true, Enabled = true, Permission = "android.permission.BIND_NFC_SERVICE", Name = "empresa1.smpay.HCECardService"), IntentFilter(new[] { "android.nfc.cardemulation.action.HOST_APDU_SERVICE" }, Categories = new[] { "android.intent.category.DEFAULT" }),
MetaData("android.nfc.cardemulation.host_apdu_service", Resource = "@xml/aid_list")]
public class HCECardService : HostApduService
{ ... }