Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Build Report Inspector generates "apkanalyzer failed to estimate the apk size. Output: Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8" exception on Build when using Java Environment Variable #29

Open
SkowronskiAndrew opened this issue Jan 6, 2023 · 2 comments

Comments

@SkowronskiAndrew
Copy link

Transferred from Jira (UUM-19493) because this ticket is a bug in the BuildReportInspector.

How to reproduce:

  1. Go to “Edit the system environment variables” > “Environment Variables…” > “New”
  2. Add “JAVA_TOOL_OPTIONS“ as a Variable name and “-Dfile.encoding=UTF-8“ as a Variable value
  3. Create a new Unity project
  4. Go to “Package Manager“ > “Add package from git URL“ and add “com.unity.build-report-inspector“ URL
  5. Build for Android
  6. After the Build is complete observe the Console

Expected result: There are no exceptions
Actual result: “System.Exception: apkanalyzer failed to estimate the apk size. Output: Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8“ exception appears

Reproducible with: 0.2.2-preview, 0.3.0-preview (2020.3.42f1, 2021.3.14f1, 2022.1.23f1, 2022.2.0b16, 2023.1.0a20)

Not reproducible on: iOS, Standalone Player (Windows 11)

Note: After setting Environment Variable a Unity Hub / PC restart may be needed

Full exception message:
System.Exception: apkanalyzer failed to estimate the apk size. Output:
18131288
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
at Unity.BuildReportInspector.Mobile.AndroidUtilities.GetApkDownloadSize (System.String applicationPath) [0x001e5] in Project Path\Library\PackageCache\com.unity.build-report-inspector@0.3.0-preview\Editor\Mobile\AndroidUtilities.cs:253
at Unity.BuildReportInspector.Mobile.AndroidUtilities.GetArchitectureInfo (System.String applicationPath) [0x000f3] in Project Path\Library\PackageCache\com.unity.build-report-inspector@0.3.0-preview\Editor\Mobile\AndroidUtilities.cs:128
at Unity.BuildReportInspector.Mobile.MobileAppendix..ctor (System.String applicationPath) [0x000d8] in Project Path\Library\PackageCache\com.unity.build-report-inspector@0.3.0-preview\Editor\Mobile\MobileAppendix.cs:90
at Unity.BuildReportInspector.Mobile.MobileHelper.GenerateMobileAppendix (System.String applicationPath, System.String guid) [0x0001e] in Project Path\Library\PackageCache\com.unity.build-report-inspector@0.3.0-preview\Editor\Mobile\MobileHelper.cs:77
UnityEngine.Debug:LogError (object)
Unity.BuildReportInspector.Mobile.MobileHelper:GenerateMobileAppendix (string,string) (at Library/PackageCache/com.unity.build-report-inspector@0.3.0-preview/Editor/Mobile/MobileHelper.cs:83)
Unity.BuildReportInspector.Mobile.MobileHelper:GenerateAndroidAppendix (string,string) (at Library/PackageCache/com.unity.build-report-inspector@0.3.0-preview/Editor/Mobile/MobileHelper.cs:27)
Unity.BuildReportInspector.Mobile.PostBuildSetup:BuildPostProcess (UnityEditor.BuildTarget,string) (at Library/PackageCache/com.unity.build-report-inspector@0.3.0-preview/Editor/Mobile/PostBuildSetup.cs:44)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Details:

Notes from Julius Miknevicius:
Build Report Inspector package tries to parse the whole apkanalyzer output as long
https://github.com/Unity-Technologies/BuildReportInspector/blob/master/com.unity.build-report-inspector/Editor/Mobile/AndroidUtilities.cs#L247

however when JAVA_TOOL_OPTIONS environment variable is specified, the output of apkanalyzer is:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
20964989 

20964989 is the size of the apk, which is what build report inspector wants.

So it seems the fix would be to improve the parsing code to strip off that possible extra junk in the output (or find a way to invoke the tool so that it doesn't add that unexpected noise in its output)

@dtaddis
Copy link

dtaddis commented Sep 9, 2023

I'm getting this same error since upgrading from Unity 2021 to 2022. I don't have a JAVA_TOOL_OPTIONS environment variable.

It technically causes my (Quest) build to fail, although the apk is produced and can be copied to the device manually.

@nick-morhun
Copy link

There is a branch named "seans/fix-jkd-issues" which has some fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants