Skip to main content

Build for Android

Unreal implements bindings for native Android webview, but those bindings are limited. There are two issues that may appear:

  • Camera does not open up because permissions are not granted.
  • Sign in with email/Google does not work (if you are using Avaturn API, you won't have this issue).

To fix this, we need to change java files in the in engine directory. It's not possible to ship those fixes as a part of SDK or example so the fixes should be applied manually. Please find below the steps to solve those problems.

Find the file

  1. Go to Unreal Engine folder to <Engine Dir>\Build\Android\Java\src\com\epicgames\unreal
  2. Open Java file - WebViewControl.java
  3. Find the definition of WebViewControl class, method run.

See below how to change this file to fix the issues.

Making camera work

Replace webView.setWebChromeClient(new ChromeClient()) with

webView.setWebChromeClient(new ChromeClient()
{
@Override
public void onPermissionRequest(final PermissionRequest request)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
request.grant(request.getResources());
}
}
});

Note that you need to request and get camera permission for the app before using the camera in webview.

Fixing login with Google

We need to change User-Agent, we use Firebase and it does not want to work with the default one. There is no straightforward way to set user agent through the API.

We need to hard-code the User-Agent in WebViewControl.java. After the lines webView.getSettings().set.. add the following row to set User-Agent:

webView
.getSettings()
.setUserAgentString(
'Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.128 Mobile Safari/537.36'
);