unity-jar-resolver icon indicating copy to clipboard operation
unity-jar-resolver copied to clipboard

DIR_UNITYPROJECT issue with paths including \u

Open sefish opened this issue 5 years ago • 9 comments

Please fill in the following fields:

Unity editor version: 2018.4.0 Play Services Resolver version: 1.2.135 Features in Play Services Resolver in use (Android Resolver, iOS Resolver, VersionHandler, etc.): Android Resolver Plugins SDK in use (Firebase, Admob, Facebook, etc.): Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows Platform you are targeting (iOS, Android, and/or desktop): Android Scripting Runtime (Mono, and/or IL2CPP): IL2CPP

Please describe the issue here:

If the Unity project path has a folder starting with a lowercase 'u', the generated build.gradle file will not compile with the error:

General error during parsing: Did not find four digit hex character code. line: 31 col:61

groovyjarjarantlr.TokenStreamIOException: Did not find four digit hex character code. line: 31 col:61

This is caused by the following line having a \u in it which is still interpreted to be a unicode escape sequence.

def unityProjectPath = $/file:///C:\Projects\test\unity/$.replace("\\", "/")

sefish avatar Mar 09 '20 15:03 sefish

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Mar 09 '20 15:03 google-oss-bot

@sefish it sounds like we should probably change the insertion of the project path based upon the Gradle version shipped with Unity as it sounds like the Gradle version with 2018.4.0 isn't interpreting dollar slashy strings correctly. '\' is not supposed to be treated as an escape character.

stewartmiles avatar Mar 09 '20 23:03 stewartmiles

@sefish just to clarify when you say the build fails, what are you using to build? Are you building in Unity itself or exporting the project and using Android Studio? If you're using Android Studio have you tried updating to see whether it parses dollar slashy strings correctly?

stewartmiles avatar Mar 09 '20 23:03 stewartmiles

@stewartmiles I've tried both building in Unity and exporting to Android Studio (v3.6.1). The issue occurs in both. I also tried using different gradle versions (4.6, 5.6, 5.6.4 and 6.2).

Just to check I downloaded groovy 2.5.10 which also throws the same parsing error. Groovy 3.0.2 seems to not have this issue although it still interprets occurences of \u with a valid unicode following it as that character.

So I dug deeper and groovy is actually interpreting the unicode escape sequences before executing the code. This means that it does not know where those sequences come from, it will replace them anywhere, even in comments: GROOVY-5674 GROOVY-6312

Also apparently this is valid groovy code:

\u0064\u0065\u0066 \u0061 \u003d \u0031\u0032\u0033

sefish avatar Mar 10 '20 11:03 sefish

I reported this as a bug to Unity too. They are probably in the best position to fix it.

sefish avatar Mar 19 '20 17:03 sefish

This does seem to be a Unity bug. However, we'll see if we can offer some workaround.

chkuang-g avatar Apr 02 '20 17:04 chkuang-g

This bug has been registered in the unity issue tracker and has been fixed for Unity2019.1 and above. https://issuetracker.unity3d.com/issues/android-windows-template-variable-dir-unityproject-on-windows-does-not-escape-slash-characters

shiena avatar Apr 17 '20 17:04 shiena

It's not the best, but it's my way around it. Add the following editor extension script to your Unity project.

#if UNITY_ANDROID
using System.IO;
using UnityEditor.Android;

public class FixPathInBuildGradle : IPostGenerateGradleAndroidProject
{
    public int callbackOrder { get; }

    public void OnPostGenerateGradleAndroidProject(string path)
    {
#if !UNITY_2019_1_OR_NEWER && UNITY_EDITOR_WIN
        var buildGradlePath = Path.Combine(path, "build.gradle");
        if (File.Exists(buildGradlePath))
        {
            var dirUnityProject = Directory.GetCurrentDirectory();
            var modDirUnityProject = dirUnityProject.Replace(@"\", "/");

            var contents = File.ReadAllText(buildGradlePath);
            var correctContents = contents.Replace(dirUnityProject, modDirUnityProject);
            File.WriteAllText(buildGradlePath, correctContents);
        }
#endif
    }
}
#endif

shiena avatar Apr 18 '20 06:04 shiena

The issue was fixed on 2018.4.24.

Android: Fix the issue that DIR_UNITYPROJECT/DIR_GRADLEPROJECT are using the wrong '' director separator on windows. (1088160)

https://unity3d.com/unity/whats-new/2018.4.24

shiena avatar Jul 03 '20 12:07 shiena