Screen squashed/stretched after Android build

Hi guys. I am new to Unity and am currently working on a simple 2d platformer app with touch-buttons on a canvas. When I test the game through the unity remote on my Samsung J2 (which has a resolution of 960 x 540) the picture looks perfect:

However when I go to the build the game and I test it as an app everything in the scene is stretched and the buttons look way too big.

I have experimented with many different resolutions and aspect ratios but every time the view is stretched, and the only difference being the different screen sizes and the buttons changing size.

I have also tried the app on 2 other android devices and on both the screen is stretched just the same.

For the above images i used an aspect ratio of 3:2 and my camera has a size of 5.
In case you need it here is the info of my Canvas:


Render Mode: Screen Space - Overlay


UI Scale Mode: Scale with Screen Size

Reference Resolution: X=800 Y=400

Screen Match Mode: Match Width or Height (I have tried 0, 0.5 and 1)

Reference Pixels per Unit: 100

After looking at many other questions from other people and trying their ideas I have still not found an answer. Is there any settings I need to change or code I need to add? Any help gratefully appreciated.

Thanks for the help guys but I worked it out myself! All I did was attach this to my camera and it works perfectly!

void Start()
		Screen.SetResolution ((int)Screen.width, (int)Screen.height, true);

Thanks again :slight_smile:

Hi you can try this script -make sure to attach it to your camera object

 public class ControllingCameraAspectScript : MonoBehaviour
     // Use this for initialization
     void Start()
         // set the desired aspect ratio (the values in this example are
         // hard-coded for 16:9, but you could make them into public
         // variables instead so you can set them at design time)
         float targetaspect = 16.0f / 9.0f;
         // determine the game window's current aspect ratio
         float windowaspect = (float)Screen.width / (float)Screen.height;
         // current viewport height should be scaled by this amount
         float scaleheight = windowaspect / targetaspect;
         // obtain camera component so we can modify its viewport
         Camera camera = GetComponent<Camera>();
         // if scaled height is less than current height, add letterbox
         if (scaleheight < 1.0f)
             Rect rect = camera.rect;
             rect.width = 1.0f;
             rect.height = scaleheight;
             rect.x = 0;
             rect.y = (1.0f - scaleheight) / 2.0f;
             camera.rect = rect;
         else // add pillarbox
             float scalewidth = 1.0f / scaleheight;
             Rect rect = camera.rect;
             rect.width = scalewidth;
             rect.height = 1.0f;
             rect.x = (1.0f - scalewidth) / 2.0f;
             rect.y = 0;
             camera.rect = rect;