Xamarin - Other

XA5104 Could not locate the Android NDK

Before start, make sure that you have already installed NDK from Visual Studio's Android SDK Manager window.


  1. Copy ndk-bundle folder from C:\Program Files (x86)\Android\android-sdk.
  2. Paste it under the C:\ProgramData\Microsoft\AndroidNDK64 path. (Create folder named AndroidNDK64 if no exists)
  3. Rename the ndk-bundle folder to android-ndk-r21.

Xamarin forms check if keyboard is open or not

Xamarin.Android

[assembly: Xamarin.Forms.Dependency(typeof(Your.Android.Namespace.KeyboardService))]

namespace Your.Android.Namespace
{
  public class KeyboardService : IKeyboardService
  {
    public event EventHandler KeyboardIsShown;
    public event EventHandler KeyboardIsHidden;

    private InputMethodManager inputMethodManager;

    private bool wasShown = false;

    public KeyboardService()
    {
      GetInputMethodManager();
      SubscribeEvents();
    }

    public void OnGlobalLayout(object sender, EventArgs args)
    {
      GetInputMethodManager();
      if(!wasShown && IsCurrentlyShown())
      {
        KeyboardIsShown?.Invoke(this, EventArgs.Empty);
        wasShown = true;
      }
      else if(wasShown && !IsCurrentlyShown())
      {
        KeyboardIsHidden?.Invoke(this, EventArgs.Empty);
        wasShown = false;
      }
    }

    private bool IsCurrentlyShown()
    {
      return inputMethodManager.IsAcceptingText;
    }

    private void GetInputMethodManager()
    {
      if (inputMethodManager == null || inputMethodManager.Handle == IntPtr.Zero)
      {
        inputMethodManager = (InputMethodManager)this.GetSystemService(Context.InputMethodService);
      }
    }

    private void SubscribeEvents()
    {
      ((Activity)Xamarin.Forms.Forms.Context).Window.DecorView.ViewTreeObserver.GlobalLayout += this.OnGlobalLayout;
    }
  }
}


Xamarin.iOS

[assembly: Xamarin.Forms.Dependency(typeof(Your.iOS.Namespace.KeyboardService))]

namespace Your.iOS.Namespace
{
  public class KeyboardService : IKeyboardService
  {
    public event EventHandler KeyboardIsShown;
    public event EventHandler KeyboardIsHidden;

    public KeyboardService()
    {
      SubscribeEvents();
    }

    private void SubscribeEvents()
    {
      UIKeyboard.Notifications.ObserveDidShow(OnKeyboardDidShow);
      UIKeyboard.Notifications.ObserveDidHode(OnKeyboardDidHide);
    }

    private void OnKeyboardDidShow(object sender, EventArgs e)
    {
      KeyboardIsShown?.Invoke(this, EventArgs.Empty);
    }

    private void OnKeyboardDidHide(object sender, EventArgs e)
    {
      KeyboardIsHidden?.Invoke(this, EventArgs.Empty);
    }
  }
}


Xamarin Forms project

public interface IKeyboardService
{
  event EventHandler KeyboardIsShown;
  event EventHandler KeyboardIsHidden;
}


Xamarin Forms page

var keyboardService = Xamarin.Forms.DependencyService.Get<IKeyboardService>();  

Xamarin forms invalid archive android ( no .APK files )

  1. Exit Visual Studio.
  2. Delete all bin and obj folders from your project.
  3. Start Visual Studio.
  4. Open your project.
  5. Clean Solution.
  6. Rebuild Solution.
  7. Archive android project.

Xamarin Forms Open File

string completeFileName = "File.txt";
string filePath = Path.Combine(FileSystem.CacheDirectory, completeFileName);

_ = Launcher.OpenAsync(new OpenFileRequest
{
  File = new ReadOnlyFile(filePath)
});

Xamarin.Android warning XA0125

Visual Studio Window

  1. Go to Properties > Build > Advanced in the project property pages.
  2. Change Debugging information to Portable.


Visual Studio Mac

  1. Go to Build > Compiler > Debug information in the project property pages.
  2. Change Debug information to Portable.


If the problematic symbol file comes from a NuGet package, update to a newer version of the package or notify the library author.

Xamarin.Forms Can't Archive because the packaging process was failed

Try to change the settings as below :

  • Linking - Change from Sdk Assemblies Only to None.
  • .csproj - Set the <AndroidEnableProfiledAot> value to true.