I am using Unity 2022.3.16f1 on Windows 11 to build and deploy an app to android (Quest 3). I hit a problem with the build where the apkanalyzer was failing with a fatal error.
System.Exception: apkanalyzer failed to estimate the apk size. Output:
Error: Could not find or load main class
This turned out to be due to apkanalyzer.bat not handling there being a space in the path (Unity was installed in C:\Program Files.
This can be fixed by editing this file:
Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6.0\bin\apkanalyzer.bat
Find this line:
@rem Add default JVM options here. You can also use JAVA_OPTS and APKANALYZER_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=-Dcom.android.sdklib.toolsdir=%~dp0\..
and add double quotes around the %~dp0..
set DEFAULT_JVM_OPTS=-Dcom.android.sdklib.toolsdir="%~dp0\.."
Alternatively install Unity in a directory with no space in the name (like C:\Tools) by configuring the relevant option in Unity Hub settings, which is what I did after testing my fix.