SpaceMadness / lunar-unity-console

High-performance Unity iOS/Android logger built with native platform UI
https://www.assetstore.unity3d.com/en/#!/content/43800
Other
839 stars 114 forks source link

Can't enable Android plugin: unable to create importer for 'Assets/LunarConsole/Editor/Android/lunar-console.aar'. Re-install Lunar Mobile Console to fix the issue. #123

Closed weeeBox closed 4 years ago

weeeBox commented 5 years ago

Mostly occurs on fresh installations

mleenhardt commented 5 years ago

We worked around this by having AndroidPlugin.SetEnabled retry in case it's unable to create an importer, which fixes the issue.

public static void SetEnabled(bool enabled, bool retrying = false)
{
    if (retrying)
    {
        EditorApplication.delayCall -= s_onRetry;
        s_onRetry = null;
    }

    var androidPathAAR = FileUtils.FixAssetPath(EditorConstants.EditorPathAndroidAAR);
    if (androidPathAAR == null || !FileUtils.AssetPathExists(androidPathAAR))
    {
        Debug.LogErrorFormat("Can't {0} Android plugin: missing required file '{1}'. Re-install {2} to fix the issue.",
            enabled ? "enable" : "disable",
            androidPathAAR,
            Constants.PluginDisplayName);
        return;
    }

    var importer = (PluginImporter)AssetImporter.GetAtPath(androidPathAAR);
    if (importer == null)
    {
        // mleenhardt: Added delayed retry attempt to fix error caused by the fact that importer is
        // null the very first time the project is loaded when there is no Library folder yet.
        if (!retrying)
        {
            s_onRetry = () => SetEnabled(enabled, true);
            EditorApplication.delayCall += s_onRetry;
            return;
        }

        Debug.LogErrorFormat("Can't {0} Android plugin: unable to create importer for '{1}'. Re-install {2} to fix the issue.",
            enabled ? "enable" : "disable",
            androidPathAAR,
            Constants.PluginDisplayName);
        return;
    }

    if (importer.GetCompatibleWithPlatform(BuildTarget.Android) != enabled)
    {
        importer.SetCompatibleWithPlatform(BuildTarget.Android, enabled);
        importer.SaveAndReimport();
    }
}
weeeBox commented 4 years ago

@mleenhardt, I've incorporated your changes into 1.6.3 release. Feel free to open a pull request in the future.

joaokucera commented 2 years ago

Hello, I am having the same issue. AssetImporter.GetAtPath(androidPathAAR) returns null even with a valid path: Packages/com.companyname.client.lunarconsole/Plugins/LunarConsole/Editor/Android/lunar-console.aar. Is there any known issue with having Lunar Console under the packages folder. We want it there in order to reuse across different games.