To do this, first you will need to install a few things.
1 java: https://www.java.com/en/download/
2 .net sdk 3.1: https://dotnet.microsoft.com/en-us/download/dotnet/3.1
3 Android Studio 4: https://developer.android.com/studio/archive scroll through this page to find version 4.0 which was released on may 28, 2020. When installing, you need to use the default path for the SDK.
After you install these, open Android Studio and in the bottom right click on configure and then SDK manager. In the SDK manager tab, install all of the most recent SDKs (select the top 10 boxes or so). Then under the SDK tools tab, select Android SDK Command-line Tools (latest) and press apply.
After this, restart your computer.
Next, go to C:/Program Files/Epic Games/<version>/Engine/Extras/Android and run SetupAndroid.bat or one of the other files depending on what operating system you use.
If you get an error saying
repositories.cfg cannot be loaded, create an empty repositories.cfg file where it is expected form the error. (C:/Users/[Username].android/repositories).
Finally, open Unreal Engine 5 and go to the android project settings. There, scroll down to the SDK config section and you need to put in your sdk and ndk locations. To get these, open android studio and open the sdk manager again. It will say your sdk location on the top. It should be something like C:\Users\westw\AppData\Local\Android\Sdk. To get your ndk location, open this path in the files app and the click on the ndk folder and the version after that. You should get something like C:\Users\westw\AppData\Local\Android\Sdk\ndk\21.4.7075529. Put these values into the settings.
You will also want to check the boxes “Package game data inside .apk?” and “Disable verify OBB on first start/update”. This is so that you do not get an error when starting your game since we did not verify these games yet.
Now you should be able to package for android and open the .apk file on your phone and install.