'Invalid Characters in Path' when attempting to build to Android

Hello,

I’ve run into an issue building to Android from Windows 7 x64. I have tried reinstalling Unity and the Android SDK multiple times and the problem still persists.

The behavior is that when building, Unity declares my path to the Android SDK invalid, clearing its preferences setting for the Android SDK path and asking me for a new one.

As soon as I do this, the build process aborts with these exceptions:

Error building Player: ArgumentException: Illegal characters in path.
UnityEditor.HostView:OnGUI()
Exception: Error building Player: ArgumentException: Illegal characters in path.
UnityEditor.BuildPlayerWindow.BuildPlayerWithDefaultSettings (Boolean askForBuildLocation, BuildOptions forceOptions) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:341)
UnityEditor.BuildPlayerWindow.GUIBuildButtons (Boolean enableBuildButton, Boolean enableBuildAndRunButton, Boolean canInstallInBuildFolder) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:942)
UnityEditor.BuildPlayerWindow.ShowBuildTargetSettings () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:923)
UnityEditor.BuildPlayerWindow.OnGUI () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:697)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.

Here’s the excerpt from the log file:

Unloading 157 unused Assets to reduce memory usage. Loaded Objects now: 1268.
System memory in use: 188.0 MB.
Unloading 13 Unused Serialized files (Serialized files now loaded: 2 / Dirty serialized files: 2)
Error building Player: ArgumentException: Illegal characters in path.
UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, BuildTarget, BuildOptions)
UnityEditor.BuildPlayerWindow:BuildPlayerWithDefaultSettings(Boolean, BuildOptions) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:339)
UnityEditor.BuildPlayerWindow:GUIBuildButtons(Boolean, Boolean, Boolean) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:942)
UnityEditor.BuildPlayerWindow:ShowBuildTargetSettings() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:923)
UnityEditor.BuildPlayerWindow:OnGUI() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:697)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
UnityEditor.HostView:Invoke(String, Object) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\DockArea.cs:213)
UnityEditor.HostView:Invoke(String) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\DockArea.cs:206)
UnityEditor.HostView:OnGUI() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\DockArea.cs:107)

[C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Src/Commands/BuildPlayerUtility.cpp line 1534] 
(Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs Line: 339)

- starting compile Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll, for buildtarget 13

*** Cancelled 'Build.Player.AndroidPlayer' in 8 seconds

Exception: Error building Player: ArgumentException: Illegal characters in path.
  at UnityEditor.BuildPlayerWindow.BuildPlayerWithDefaultSettings (Boolean askForBuildLocation, BuildOptions forceOptions) [0x001b1] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:341 

  at UnityEditor.BuildPlayerWindow.GUIBuildButtons (Boolean enableBuildButton, Boolean enableBuildAndRunButton, Boolean canInstallInBuildFolder) [0x0006d] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:942 

  at UnityEditor.BuildPlayerWindow.ShowBuildTargetSettings () [0x0054f] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:923 

  at UnityEditor.BuildPlayerWindow.OnGUI () [0x000f9] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\BuildPlayerWindow.cs:697 

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception)

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 

  at UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) [0x0000f] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\DockArea.cs:213 

  at UnityEditor.HostView.Invoke (System.String methodName) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\DockArea.cs:206 

  at UnityEditor.HostView.OnGUI () [0x00058] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\DockArea.cs:107 
 
(Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs Line: 341)

- Finished compile Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll
- starting compile Library/ScriptAssemblies/Assembly-UnityScript.dll, for buildtarget 13
- Finished compile Library/ScriptAssemblies/Assembly-UnityScript.dll
Non platform assembly: data-0EFBD1D8 (this message is harmless)
Non platform assembly: data-0F2DCF38 (this message is harmless)
Platform assembly: C:\dev\Unity\Data\Mono\lib\mono\2.0\I18N.dll (this message is harmless)
Platform assembly: C:\dev\Unity\Data\Mono\lib\mono\2.0\I18N.West.dll (this message is harmless)
Mono: successfully reloaded assembly
NullReferenceException: Object reference not set to an instance of an object
  at UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r, Int32 button) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:180 

  at UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:175 

  at UnityEditor.ListViewShared+ListViewElementsEnumerator.MoveNext () [0x0000c] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:368 

  at UnityEditor.ConsoleWindow.OnGUI () [0x00386] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\ConsoleWindow.cs:422 

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception)

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
 
(Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/ListViewShared.cs Line: 180)

NullReferenceException: Object reference not set to an instance of an object
  at UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r, Int32 button) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:180 

  at UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:175 

  at UnityEditor.ListViewShared+ListViewElementsEnumerator.MoveNext () [0x0000c] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:368 

  at UnityEditor.ConsoleWindow.OnGUI () [0x00386] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\ConsoleWindow.cs:422 

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception)

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
 
(Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/ListViewShared.cs Line: 180)

NullReferenceException: Object reference not set to an instance of an object
  at UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r, Int32 button) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:180 

  at UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r) [0x00000] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:175 

  at UnityEditor.ListViewShared+ListViewElementsEnumerator.MoveNext () [0x0000c] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\GUI\ListViewShared.cs:368 

  at UnityEditor.ConsoleWindow.OnGUI () [0x00386] in C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\Mono\ConsoleWindow.cs:422 

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception)

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
 
(Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/ListViewShared.cs Line: 180)

This issue only occurs when attempting to build to Android; I can build to standalone and web players without any problems, but it occurs on EVERY project, even one consisting of just the default scene. I have reinstalled Unity, scrubbing the registry of the entries I could find, as well as the Android SDK. I have also moved all of the paths around to avoid anything that could POSSIBLY be legitimately invalid – for example, Unity and the Android SDK both live in C:\Dev\ instead of good old Program Files (x86), etc.

As a side note, random (disturbing) exceptions appear intermittently throughout Unity. For example, double-clicking on an error in the console gives me this:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r, Int32 button) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/ListViewShared.cs:180)
UnityEditor.ListViewShared.HasMouseDown (UnityEditor.InternalListViewState ilvState, Rect r) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/ListViewShared.cs:175)
UnityEditor.ListViewShared+ListViewElementsEnumerator.MoveNext () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/ListViewShared.cs:368)
UnityEditor.ConsoleWindow.OnGUI () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/ConsoleWindow.cs:422)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

So, it seems like something is seriously and fundamentally screwed with Unity on this computer.

Please help – I’ve uninstalled and reinstalled everything that seems directly relevant and I’m not sure what else to try. This is my main Unity dev system and so my next step is pretty much to reinstall Windows unless someone here has a suggestion, and I have no idea where the disc is. :wink:

Thanks,
-Umo

Also, if you’re wondering, the Android SDK seems fine – I can build and deploy Android projects from Eclipse without problems.

Any ideas?

The same issue… Yesterday it was fine, but today I can not build any project for Android. Could it be a Unity software update or something got broken in the configs?

Resolved… It was crashing when trying to combine JAVA_HOME and ‘bin’. Just removed quotes from JAVA_HOME environment variable value and it is fine now.

Argh. I had tried adding quotes into the Java entry in my path, but not removing them from the JAVA_HOME. I’ll try this tonight when I get home – thanks!

Confirmed resolved. Stupid JAVA_HOME. Stupid Microsoft for inflicting “Program Files (x86)” on us all. Stupid me for trying to be defensive with my environment variable definitions. Bah.

Not to bump for no reason, but I’ve tried all of the path-renaming tricks above, to no avail. The log file still gives me the following:

Error building Player: ArgumentException: Illegal characters in path.
 
(Filename:  Line: -1)

If the editor would have been kind enough to mention which file, that would have been handy, but alas…

Using Unity 4.2.0f4
Android SDK Tools rev 22.0.5

I’m having the same problem but I don’t have quotes.

I don’t get the general idea of the part "Resolved… It was crashing when trying to combine JAVA_HOME and ‘bin’. "

Could any one put it into other words?.

Thanks in advance and kind regards :slight_smile:

What was happening to them was that they had an environment variable called “JAVA_HOME” set to something like “C:\Java”. When Unity builds the Android .apk, it tries to find some Java tools in the Java path, which it creates by appending “bin” to the value of JAVA_HOME. So, in the above case, it would look in the folder “C:\Javabin”, which doesn’t exist – you have to set JAVA_HOME to something like "C:\Java" with the trailing slash to make sure that Unity looks in the folder C:\Java\bin, which DOES exist (or should). So, everyone above was just making sure they had the trailing slash in their JAVA_HOME variables.

I should note that these directories are different for just about everyone; also, adding the slash to my own environment variable didn’t help, and I’m still having this problem.

After reading other thread ( http://forum.unity3d.com/threads/192189-Unity3d-4-2-Invalid-Characters-in-Path ) I have tried other work around and It worked! :smile:.
1-Download android sdk r21 : https://dl.google.com/android/android-sdk_r21-windows.zip
2- Unzip in a different place than your usual android sdk.
3- In android-sdk_r21, install the Android 4.0 SDK Platform (only)
4- Select the android-sdk_r21 folder as android sdk in Unity
5- Enjoy

It seems to be some kind of problem with sdk r22. I hope it helps!.

Wow, that worked like a charm. I’d tried variants on this approach before, but I must have gotten one or two steps wrong, previously. Thanks for laying it out so simply!

Thanks, this fixed it for me too. 4.1 worked fine so this was really annoying, and the latest 4.2.1 still had the same problem.

I’m glad to hear that :slight_smile:

Thank you so much! nekete! :slight_smile: this worked for me… now i just have to remember for next time !

Take care and good luck on your projects

Not sure if this is directly related to your error, but this is how i resolved this error when i encountered it:
http://www.tallior.com/2014/02/08/bug-hunting-unity-throws-an-argumentexception-when-building-for-android/

I don’t want to bump this for no reason, but I was still having problems, even when I did everything anyone has ever suggested as a fix.
I fixed it like this:
JDK was in C:\Program Files (x86)\jdksomething, so I copied the jdk folder to C:, and went to my environment variables and changed the JAVA_HOME to C:\jdkfolder\ (the last slash is important), and it stopped showing the error ever since, even with the r22 sdk!

Hope I helped.