boot – Stuck in the installation of "grub2 package"

I'm trying to install Ubuntu 18.04.1 as my second operating system for my HP Pavilion x360. The installation method I am using is "install together with the Windows boot manager".

My installation stops at "installing grub2 packages". The console would say "Installation for the x86_64-efi platform."and come back"Warning: source ID n was not found when trying to delete it"where n is some number.

I tried installing with and without secure boot and legacy mode and I created multiple boot USBs using rufus, Universal USB installer, boot disk creator (through Ubuntu VirtualBox) and Etcher, but the results are the same.

I've also tried installing Ubuntu alone and that works, but I still need a boot loader to boot into the operating system.