How to root an Android emulator My application required to use some system command such as wm size and wm size reset to change the screen size so an application supposed be running on Portrait only mode will be displayed as portrait in a landscape screen. 

I have gone through many of the answer in stack overflow but still can't get an idea of how to do it.

Somebody can give me a step by step guide how to achieve this thanks. I've tried the Andydroid emulator but still not work.

I know the emulator is rooted when using adb console but looks like if I test it with my program, it was not.
I have found the way to root. Only work on certain API Level stated in their answer.

Attempt to root AVD running Android 4.4/5.1 is failing