UnityTips: How To Select The Graphics API Based On The Current Android Device

Jiadong Chen
The Programmer In Kiwiland
3 min readJun 11, 2020

--

With more and more Android phones supporting both GLES and Vulkan, mobile game developers often face a problem, can we select which Graphics API to use when the game is launched on a specific device?

The short answer is YES.

Let’s Select the Right Graphics API At Runtime

After Unity 2018.4, Unity provides the function of adding command-line arguments in UnityPlayerActivity. You can add command-line arguments. such as -force-gles20, -force-gles30, -force-gles31, -force-gles31aep and -force-vulkan to force use the selected Graphics API.

You can export the project and open it in Android Studio, then modify the UnityPlayerActivity.java file. There is an example:

String deviceName = android.os.Build.MODEL;


// Setup activity layout
@Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);

if(deviceName.equals("SM-C9000"))
{
this.getIntent().putExtra("unity", "-force-gles30");
}

mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}

Here, I use the relatively old Samsung Device SM-C9000. And build the project with Vulkan and OpenGLES graphics API. I want to select the relatively old Graphics API on this old device, so I set the command-line…

--

--

Jiadong Chen
The Programmer In Kiwiland

Microsoft MVP, MCT | Azure Certified Solutions Architect & Cybersecurity Architect Expert | Member of .NET Foundation | Packt Author