Error compiling for Android

I was curious to see flax running on android, so I followed the documentation and configured my environment with the following requirements:

JAVA_HOME - 19.0.2
ANDROID_NDK - r25c
ANDROID_HOME - 22.1.1.21
GRADLE - 8.0.2 In the docs it wasn't described about gradle.

LOG:

  • Highlights
[ 00:03:03.769 ]: [Info] Top assets types stats:
[ 00:03:03.769 ]: [Info] FlaxEngine.Texture                 :   23 assets of total size 149.20000000000002 MB
[ 00:03:03.769 ]: [Info] FlaxEngine.SkinnedModel            :    2 assets of total size 25.97 MB
[ 00:03:03.770 ]: [Info] FlaxEngine.Shader                  :   30 assets of total size 1.75 MB
[ 00:03:03.770 ]: [Info] FlaxEngine.Material                :   33 assets of total size 1.4000000000000001 MB
[ 00:03:03.770 ]: [Info] FlaxEngine.Animation               :   12 assets of total size 533.92 KB
[ 00:03:03.770 ]: [Info] FlaxEngine.CubeTexture             :    1 assets of total size 512.52 KB
[ 00:03:03.770 ]: [Info] FlaxEngine.Model                   :    7 assets of total size 383.84000000000003 KB
[ 00:03:03.770 ]: [Info] FlaxEngine.FontAsset               :    1 assets of total size 168.06 KB
[ 00:03:03.770 ]: [Info] FlaxEngine.RawDataAsset            :    1 assets of total size 61.54 KB
[ 00:03:03.770 ]: [Info] FlaxEngine.JsonAsset               :   16 assets of total size 13.8 KB
[ 00:03:03.772 ]: [Info] Android permissions:
[ 00:03:03.772 ]: [Info]    android.permission.READ_EXTERNAL_STORAGE
[ 00:03:03.772 ]: [Info]    android.permission.WRITE_EXTERNAL_STORAGE
[ 00:03:03.772 ]: [Info]    android.permission.INTERNET
[ 00:03:03.868 ]: [Info] Exporting texture to 'C:\dev/flax/Unlost/Output/Android/app/src/main/res/mipmap/icon.png'.
[ 00:03:03.872 ]: [Info] Texture exported in 4 ms
[ 00:03:03.932 ]: [Info] Exporting texture to 'C:\dev/flax/Unlost/Output/Android/app/src/main/res/mipmap-hdpi/icon.png'.
[ 00:03:03.934 ]: [Info] Texture exported in 2 ms
[ 00:03:03.989 ]: [Info] Exporting texture to 'C:\dev/flax/Unlost/Output/Android/app/src/main/res/mipmap-mdpi/icon.png'.
[ 00:03:03.991 ]: [Info] Texture exported in 2 ms
[ 00:03:04.047 ]: [Info] Exporting texture to 'C:\dev/flax/Unlost/Output/Android/app/src/main/res/mipmap-xhdpi/icon.png'.
[ 00:03:04.050 ]: [Info] Texture exported in 3 ms
[ 00:03:04.097 ]: [Info] Exporting texture to 'C:\dev/flax/Unlost/Output/Android/app/src/main/res/mipmap-xxhdpi/icon.png'.
[ 00:03:04.099 ]: [Info] Texture exported in 2 ms
[ 00:03:04.154 ]: [Info] Exporting texture to 'C:\dev/flax/Unlost/Output/Android/app/src/main/res/mipmap-xxxhdpi/icon.png'.
[ 00:03:04.157 ]: [Info] Texture exported in 3 ms
[ 00:03:04.209 ]: [Info] Building Gradle project into package...
[ 00:03:04.209 ]: [Info] Command: "C:\dev/flax/Unlost/Output/Android/gradlew.bat" assembleDebug
[ 00:03:04.209 ]: [Info] Working directory: C:\dev/flax/Unlost/Output/Android
[ 00:03:06.094 ]: [Error] Failed to build Gradle project into package (result code: 1). See log for more info.
[ 00:03:06.094 ]: [Error] Game building failed

That’s odd. You can go to C:\dev/flax/Unlost/Output/Android/ folder and run gradlew.bat script manually (optionally with assembleDebug command argument) via Console (cmd.exe on Windows). For some, strange reason there is no output from that script running from Editor so I don’t know what’s going on there.

@mafiesto4 I’m found exceptions

  • Output/Android

Captura de ecrĂŁ 2023-04-12 075853

  • Console
// EntryPoint
$ ./gradlew.bat assebleDebug
// EndPoint
PS C:\dev\flax\Unlost\Output\Android> .\gradlew.bat assebleDebug

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.5/userguide/gradle_daemon.html
Process command line: C:\App\OpenJDK\19.0.2\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\aleci\.gradle\wrapper\dists\gradle-6.5-bin\3gc46ktsbbn1a7ktgl9fgomcgl\gradle-6.5\lib\gradle-launcher-6.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.5
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org```
// EntryPoint
$ ./gradlew.bat assebleDebug --debug
// Endpoint & Highlights
$ ./gradlew.bat assebleDebug --debug

// Part-1
2023-04-12T08:23:34.651+0200 [INFO] [org.gradle.internal.nativeintegration.services.NativeServices] Initialized native services in: C:\Users\aleci\.gradle\native
2023-04-12T08:23:34.769+0200 [LIFECYCLE] [org.gradle.launcher.cli.DebugLoggerWarningAction]
#############################################################################
   WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

   Debug level logging will leak security sensitive information!

   https://docs.gradle.org/6.5/userguide/logging.html#sec:debug_security
#############################################################################

2023-04-12T08:23:34.800+0200 [DEBUG] [org.gradle.internal.nativeintegration.services.NativeServices] Native-platform posix files integration is not available. Continuing with fallback.
2023-04-12T08:23:35.067+0200 [DEBUG] [org.gradle.launcher.daemon.client.DaemonClient] Executing build 03139cba-aca3-4060-bc8e-04f692755d4b in daemon client {pid=7248}
2023-04-12T08:23:35.086+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface Software Loopback Interface 1
2023-04-12T08:23:35.090+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? true
2023-04-12T08:23:35.093+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding loopback address /127.0.0.1
2023-04-12T08:23:35.094+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding loopback address /0:0:0:0:0:0:0:1
2023-04-12T08:23:35.095+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface Microsoft Kernel Debug Network Adapter
2023-04-12T08:23:35.099+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2023-04-12T08:23:35.100+0200 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface Microsoft 6to4 Adapter
// continue...

// Parte-2
2023-04-12T08:23:35.411+0200 [LIFECYCLE] [org.gradle.launcher.daemon.client.DefaultDaemonConnector] Starting a Gradle Daemon (subsequent builds will be faster)
2023-04-12T08:23:35.465+0200 [DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Using daemon args: [C:\App\OpenJDK\19.0.2\bin\java.exe, -XX:MaxPermSize=512m, -XX:+HeapDumpOnOutOfMemoryError, --add-opens, java.base/java.util=ALL-UNNAMED, --add-opens, java.base/java.lang=ALL-UNNAMED, --add-opens, java.base/java.lang.invoke=ALL-UNNAMED, --add-opens, java.prefs/java.util.prefs=ALL-UNNAMED, -Xmx2048m, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant, -cp, C:\Users\aleci\.gradle\wrapper\dists\gradle-6.5-bin\3gc46ktsbbn1a7ktgl9fgomcgl\gradle-6.5\lib\gradle-launcher-6.5.jar]
2023-04-12T08:23:35.473+0200 [DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Starting daemon process: workingDir = C:\Users\aleci\.gradle\daemon\6.5, daemonArgs: [C:\App\OpenJDK\19.0.2\bin\java.exe, -XX:MaxPermSize=512m, -XX:+HeapDumpOnOutOfMemoryError, --add-opens, java.base/java.util=ALL-UNNAMED, --add-opens, java.base/java.lang=ALL-UNNAMED, --add-opens, java.base/java.lang.invoke=ALL-UNNAMED, --add-opens, java.prefs/java.util.prefs=ALL-UNNAMED, -Xmx2048m, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant, -cp, C:\Users\aleci\.gradle\wrapper\dists\gradle-6.5-bin\3gc46ktsbbn1a7ktgl9fgomcgl\gradle-6.5\lib\gradle-launcher-6.5.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 6.5]
// continue...

// Part-3
#############################################################################
   WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

   Debug level logging will leak security sensitive information!

   https://docs.gradle.org/6.5/userguide/logging.html#sec:debug_security
#############################################################################

2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Unable to start the daemon process.
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] This problem might be caused by incorrect configuration of the daemon.
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] For example, an unrecognized jvm option is used.
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.5/userguide/gradle_daemon.html
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Process command line: C:\App\OpenJDK\19.0.2\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\aleci\.gradle\wrapper\dists\gradle-6.5-bin\3gc46ktsbbn1a7ktgl9fgomcgl\gradle-6.5\lib\gradle-launcher-6.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.5
2023-04-12T08:23:35.601+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Please read the following process output to find out more:
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] -----------------------
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Unrecognized VM option 'MaxPermSize=512m'
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Error: Could not create the Java Virtual Machine.
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Error: A fatal exception has occurred. Program will exit.
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.  Run with --scan to get full insights.
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
2023-04-12T08:23:35.602+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org
// end

Thanks, that gives more information. It looks like issue with Gardle Java Deamon. Maybe somebody on the Internet got similar problem. Like here: java - Android Studio Gradle project "Unable to start the daemon process /initialization of VM" - Stack Overflow

1 Like

That’s not it, I managed to compile the apk, and the problem was the java version. Since I didn’t know which version of java I should use, I ended up using java version 19.0.2 as described in the documentation for flax.
After changing JAVA_HOME to C:\Program Files\Android\Android Studio\jbr
it ended up working and the version of java that Android Studio is using or rather the version that FlaxEngine v1.5 needs is JAVA >= 20


Despite compiling the project on the cell phone, it was all blocked and the screen flickered and ended up bugging the cell phone.
Error seen:

  1. It didn’t load a level (in the windows build the main screen loads a new level which in the android build stuck on the same screen)

  2. Phone crash (my phone is medium [4GBx128GB, GPU: Vulkan 1.1 & 90 (FPS) Refresh Rate, CPU: Mediatek G35 & Arm64-v8a * armeabi-v7a)
    Some warnings:
    On the first boot it stuck my background image, stopped recognizing USB, and I had to restart the phone. considering that despite being medium, it runs several games until it is heavy!

Bug - background image

Build - Android

Build - Win64

  1. It didn’t load the level for some reason, in the android build the game was stuck on the initial screen and didn’t change the level.

  2. The screen rotates automatically, this point is not really a problem but the game/build for android rotates in every cent horizontally/vertically the ideal is to just rotate horizontally “maybe I don’t know how to configure that :thinking:”

These were some of the problems I found considering that I couldn’t even open the gameplay level.

Okay that’s a progress. Now you can use adb tool from Android SDK to gather logs from game build so we will know why the level doesn’t load (probably something crashed :smiley: ).
Docs: Android | Flax Documentation

1 Like

I’m sorry for the delay, I didn’t even know what adb is, so I had to study a little until I could use it, but I managed to capture the log and it’s hosted at “pastebin.com”. link below.

Build log > Pastebin.com

"What I think s that there is a problem with the null reference"


According to the log this script is involved, it helps to keep the same size and position of the UI.
I will remove this script and recompile the project😂

using FlaxEngine;
using FlaxEngine.GUI;

namespace Game
{
    [ExecuteInEditMode]
    public class NormalScale : Script
    {
        public enum MatchMode { Width, Height, Merge }
        public enum UpdateMode { OnEnable, OnUpdate }

        public int baseWidth = 1920;
        public int baseHeight = 1080;

        [Space(10)]
        public UpdateMode updateMode = UpdateMode.OnUpdate;
        public MatchMode matchMode = MatchMode.Merge;

        [Space(10)]
        public UIControl scalerControl;

        private CanvasScaler scaler;
        private Vector2 result, viewport, resolution;
        public bool init;


        internal void Init()
        {
            if (init || scalerControl == null) return;

            try
            {
                scaler = scalerControl.Get<CanvasScaler>();
                scaler.Scaling = CanvasScaler.ScalingMode.ConstantPixelSize;
                init = true;
            }
            catch { }
        }

        internal float Calc()
        {
            result = (viewport / resolution);

            switch (matchMode)
            {
                case MatchMode.Width: return result.X;
                case MatchMode.Height: return result.Y;
                case MatchMode.Merge: return (result.X + result.Y) / 2f;
                default: return 1;
            }
        }

        internal void Fix()
        {
            if (init)
            {
                resolution = new Vector2(baseWidth, baseHeight);

                viewport = new Vector2(Screen.Size.X, Screen.Size.Y);

                scaler.ScaleFactor = Calc();
            }
            else
            {
                Init();
            }
        }

        public override void OnEnable()
        {
            if (updateMode == UpdateMode.OnEnable) Fix();
        }

        public override void OnLateUpdate()
        {
            if (updateMode == UpdateMode.OnUpdate) Fix();
        }
    }
}

I fixed any bugs in the project so that there are no exceptions, then I compiled it again. The result did not change my cell phone is very slow after opening it, I tried to run it on an android emulator “Bluestacks” but the result did not change.
Build log > Pastebin.com

It does not load the level and the script I use to load the level is here below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using FlaxEngine;
using FlaxEngine.GUI;

namespace Game
{
    public class LoadScene : Script
    {
        public SceneReference nextScene;
        [Range(0, 10)]
        public float delay = 3;
        [Header("Manual Loading")]
        public Button button;

        public override void OnStart()
        {
            Task task = new Task(async () =>
            {
                await Task.Delay((int)(delay * 1000f));
                Scripting.InvokeOnUpdate(() =>
                {
                    Level.ChangeSceneAsync(nextScene);
                });
            });

            if (button == null)
            {
                task.Start();
            }
            else
            {
                button.Clicked += () => task.Start();
            }
        }
    }
}

To clear my doubts I created a new project and added a script that just loads the OnStart of the “Main Scene” calling Level.ChangeSceneAsync(newScene); where newScene is a variable of type SceneReference that is defined in the inspector, the game worked in the editor and in the build for windows when I compiled it for android it only gave a black screen and I also tried it on two different android emulators and it gave the same result.

Yeah that null reference error was causing the problem on startup.
Does it work on a phone now? Can you see the scene being loaded and drawn on a screen? The log looks better now and the game should work on your phone.
Emulators might not work well - I haven’t tried them at all, only real phones.

1 Like

It’s not working, as in the comment above where I say: that I create a new project with just a level loading script, but it didn’t work and it kept crashing my cell phone. and something strange is that the default flaxengine welcome screen didn’t even appear in both builds for android.

It might be something with that Android device GPU since you cannot see any splashscreen or scene view. But the log looks fine and Vulkan driver for PowerVR Rogue GE8320 GPU looks ok. Although, I never tested PowerVR GPU on Android device.

Why isn’t running on emulator using DirectX and OpenGL? I try it on others devices but isn’t working

@mafiesto4 Have you ever tried to compile and run a flax 1.5 app on android device?

Yes every Flax update is verified to run properly all Flax Samples projects on Android phone and I test with OnePlus 7 device.

I’ve tested the graphics demo and it works on a Snapdragon Galaxy S10 with Adreno.

I understand. Flax is using the new render technologies “PowerVR”. My android device and android emulator like “BlueStacks” don’t have support for this technology.