The problem is when you are connected through the router, the androidwifi in your emulator uses the settings and the sets the DNS to something other than 8.8.8.8 which is the google DNS(I presume this is kinda mandatory setting for the androidwifi to gain internet access).
HOW TO RUN THE EMULATOR IN ANDROID STUDIO ON A MAC FOR MAC
Note: For Mac users, if the entries field is disabled and you're not able to edit it, click on the 'Lock' icon in the bottom area of that window and enter the password to be able to make changes > DNSĭelete whatever entries you have there and add these two entries (Screenshot below): 8.8.8.8
Set the Preferred and Alternate DNS servers as (Screenshot below) : 8.8.8.8