How to set location & make it work for emulator and real device

I want to set the location during test run to be in Dubai , How can i make this work without any fake location apps ?

i searched a lot but found outdated methods and deprecated functions so how i can achieve this ?

BTW i’m using java language