Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Error XA2006 TargetFrameworkVersion Android 10 #182

Open
pzavala26 opened this issue Sep 3, 2020 · 1 comment
Open

Error XA2006 TargetFrameworkVersion Android 10 #182

pzavala26 opened this issue Sep 3, 2020 · 1 comment

Comments

@pzavala26
Copy link

pzavala26 commented Sep 3, 2020

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: 6.0.1
Device Tested On:
Simulator Tested On:
Version of VS: 16.7.5
Version of Xamarin: 4.7.0.1142
Versions of other things you are using:
xamarin.essentials: 1.5.3.2

Steps to reproduce the Behavior

android:minSdkVersion="16"
android:targetSdkVersion="29"
TargetFrameworkVersion: android 10

Expected Behavior

Actual Behavior

This is On Release Mode
Using plugin version 6.0.1 throws error
error XALNK7000: Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: No se pudo resolver la referencia a "Plugin.Permissions.BasePermission" (definida en el ensamblado "ProjectMovil", Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") con el ámbito "Plugin.Permissions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"'. Cuando el ámbito es diferente del ensamblado de definición, normalmente significa que el tipo se reenvía. ---> Mono.Cecil.ResolutionException: Failed to resolve Plugin.Permissions.BasePermission

When using Old version plugin 3.0.0.12 works!

Code snippet

using Plugin.Permissions;
using Plugin.Permissions.Abstractions;
using System;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace ProjectMovil.Util
{
public class Permisos
{
public static async Task TienePermisoAlmacenamiento()
{
return await TienePermiso(new StoragePermission(), Permission.Storage);
}

    public static async Task<bool> TienePermisoCalendario()
    {
        return await TienePermiso(new CalendarPermission(), Permission.Calendar);
    }

    public static async Task<bool> TienePermisoCamara()
    {
        return await TienePermiso(new CameraPermission(), Permission.Camera);
    }

    public static async Task<bool> TienePermisoContactos()
    {
        return await TienePermiso(new ContactsPermission(), Permission.Contacts);
    }

    public static async Task<bool> TienePermisoFotos()
    {
        return await TienePermiso(new PhotosPermission(), Permission.Photos);
    }

    public static async Task<bool> TienePermisoLibreria()
    {
        return await TienePermiso(new MediaLibraryPermission(), Permission.MediaLibrary);
    }

    public static async Task<bool> TienePermisoMicrofono()
    {
        return await TienePermiso(new MicrophonePermission(), Permission.Microphone);
    }

    public static async Task<bool> TienePermisoTelefono()
    {
        return await TienePermiso(new PhonePermission(), Permission.Phone);
    }

    public static async Task<bool> TienePermisoUbicacion()
    {
        return await TienePermiso(new LocationPermission(), Permission.Location);
    }

    private static async Task<bool> TienePermiso(BasePermission basePermiso, Permission permiso)
    {
        try
        {
            var permissionStatus = await basePermiso.CheckPermissionStatusAsync();

            if (permissionStatus != PermissionStatus.Granted)
            {
                permissionStatus = await basePermiso.RequestPermissionAsync();

                if (permissionStatus != PermissionStatus.Granted)
                {
                    var result = await CreateDialog(permiso);

                    if (result)
                    {
                        CrossPermissions.Current.OpenAppSettings();
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            return permissionStatus == PermissionStatus.Granted;
        }
        catch (Exception ex)
        {
            throw new Exception(ex);
        }
    }

    private static Task<bool> CreateDialog(Permission permission)
    {
        var permisoDesc =
            permission == Permission.Contacts ? "Contactos" : (
            permission == Permission.Location ? "Ubicación" : (
            permission == Permission.Phone ? "Teléfono" : (
            permission == Permission.Camera ? "Cámara" : (
            permission == Permission.Photos ? "Fotos" : (
            permission == Permission.Storage ? "Almacenamiento" : (
            permission == Permission.Calendar ? "Calendario" : (
            permission == Permission.Microphone ? "Micrófono" : (
            permission == Permission.MediaLibrary ? "Libreria" : string.Empty))))))));

        var question = $"Es necesario dar permiso a {permisoDesc} para continuar e intente hacer la operación nuevamente.";
        var positive = "Configuración";
        var negative = "Ignorar";

        return Application.Current?.MainPage?.DisplayAlert("Permisos", question, positive, negative);
    }
}

}

Screenshots

@pzavala26
Copy link
Author

help?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant