playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.45k stars 963 forks source link

Package failing to import on Unity 2021.3.2f1 with error "com.google.play.games folder was renamed" #3163

Open frankvHoof93 opened 2 years ago

frankvHoof93 commented 2 years ago

It appears that there was some change in Unity between Unity 2018.4 and Unity 2021.3 that's causing the following line in GPGSUtil.cs to not return any results (this is at the top of the Getter for RootPath): string[] dirs = Directory.GetDirectories("Packages", RootFolderName, SearchOption.AllDirectories); where RootFolderName = com.google.play.games This works fine and returns the proper folder in Unity 2018, but returns nothing in Unity 2021, causing the import of the Package to fail (when imported as a Package via the manifest.json).

Calling Path.GetFullPath($"Packages/{RootFolderName}") actually DOES resolve to a proper path. Thus, this bug can be resolved by the following code:

string[] dirs = Directory.GetDirectories("Packages", RootFolderName, SearchOption.AllDirectories);
string path = Path.GetFullPath($"Packages/{RootFolderName}");
if (path != null)
{
    List<string> currDirs = new List<string>(dirs)
    {
        path
     };
     dirs = currDirs.Distinct().ToArray();
}

Which will add a 'working' path to the Array and cause the import to succeed. Of course this isn't the cleanest way to resolve it. However: It does show that newer Unity-Versions require the usage of Path (or potentially AssetDatabase?) to search for the package-directory.

Additional Details:

The Package is added as a Local Package (via Package Manager->Add from disk->manifest.json) for both versions of Unity.

Here's the code I added to GPGSUtil.cs -> RootPath to check this issue: image

When this runs in Unity 2018.4.36f1 I get the following result: image

In Unity 2021.3.2f1 the same code results in: image And not manually adding the (proper) Path results in the Plugin error that's at the top of the switch-statement. image Along with the following Console-Output: image

frankvHoof93 commented 2 years ago

I spotted a second bug: The ManifestRelativePath in the same script is relative to the Package Root Directory. However: The package isn't necessarily part of the project folder structure, whereas the AndroidManifest.xml should be in the Assets-folder. Thus; this Path should be made relative to the Assets-folder or the Project-Folder, not the Package-Folder.

I managed to resolve this by changing the ManifestRelativePath to: private const string ManifestRelativePath = "Plugins/Android/GooglePlayGamesManifest.androidlib/AndroidManifest.xml"; As well as updating ManifestPath to:

private static string ManifestPath
{
    get { return SlashesToPlatformSeparator(Path.Combine("Assets", ManifestRelativePath)); }
}
andreparodi-bandai commented 1 year ago

I am using version 0.11.1 installing it from our private upm repository and can confirm I have the same issue described here.

I applied both fixes and it's working. As @frankvHoof93 described, the fact that packages downloaded from upm are in /Library/PackageCache instead of /Assets/Packages is what's causing the problem.