- Home /
Cloud build Android failing after upgrading to 2018 LTS (UnityException: HasKey)
Hi,
Android and iOS were building fine with Unity 2018.2.20f1.
I upgraded to Unity 2018.40f1 (LTS). Upgraded a few asset store packages to remove errors from assets. When finished, editor has no compile or run-time errors.
iOS is now building fine for LTS.
Android build is failing because of this error which shows up 3 times in the cloud build log:
.
[Unity] UnityException: HasKey can only be called from the main thread. [Unity] at UnityEditor.Android.AndroidSDKTools.RunSDKToolWithReadLock (System.String[] command, System.String workingdir, System.String errorMsg) [0x00000] in :0
.
Here is the full log, notice UnityEditor.EditorPrefs:HasKey.
.
23099: [Unity] UnityException: HasKey can only be called from the main thread. 23100: [Unity] Constructors and field initializers will be executed from the loading thread when loading a scene. 23101: [Unity] Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. 23102: [Unity] at (wrapper managed-to-native) UnityEditor.EditorPrefs:HasKey (string) 23103: [Unity] at UnityEditor.Android.AndroidJavaRoot.get_UseEmbedded () [0x00000] in :0 23104: [Unity]
at UnityEditor.Android.AndroidJavaRoot.GetRootDirectory () [0x00000] in :0 23105: [Unity]
at UnityEditor.Android.AndroidJavaTools.GetInstance (Boolean browse) [0x00000] in :0 23106: [Unity] at UnityEditor.Android.AndroidSDKTools.RunSDKToolWithReadLock (System.String[] command, System.String workingdir, System.String errorMsg) [0x00000] in :0 23107: [Unity] at UnityEditor.Android.PostProcessor.Tasks.BuildAPK+Builder.BuildPackage (UnityEditor.Android.PostProcessor.Tasks.BuilderContext context, System.String abi, System.String& output) [0x00000] in :0 23108: [Unity] at UnityEditor.Android.PostProcessor.Tasks.BuildAPK+Builder.Build (UnityEditor.Android.PostProcessor.Tasks.BuilderContext context, System.String abi, System.String& output) [0x00000] in :0 23109: [Unity] at UnityEditor.Android.PostProcessor.Tasks.BuildAPK+Builder+c_AnonStorey0.<>m_0 () [0x00000] in :0
.
Please help!
Thanks
.
EDIT I have ensured that all occurrences of EditorPrefs.HasKey, EditorPrefs.Get~, and EditorPrefs.Set~ are wrapped in platform defines #if UNITY_EDITOR && !UNITY_CLOUD_BUILD. No improvement.
.
EDIT I hear android builds should not use "internal", but only "gradle". Gradle builds are completing without build errors, but when installed on device its broken.
Your answer
