【问题标题】:Android build error "failed to create JavaTypeInfo for class" :XamarinAndroid 构建错误“无法为类创建 JavaTypeInfo”:Xamarin
【发布时间】:2020-03-05 06:49:06
【问题描述】:

按照本教程https://github.com/Vidyo/vidyo.io-connector-xamarin我下载了应用程序,没有做任何更改。

当我构建应用程序时,我收到以下错误:

严重性代码描述项目文件行抑制状态 错误无法为类创建 JavaTypeInfo:Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/ITouchExplorationStateChangeListenerImplementor 由于 MAX_PATH:System.IO.DirectoryNotFoundException:找不到路径的一部分'C:\Users\User\Desktop\vidyo .io-connector-xamarin-master\vidyo.io-connector-xamarin-master\VidyoConnector.Android\obj\Debug\90\android\src\mono\android\support\v4\view\accessibility\AccessibilityManagerCompat_TouchExplorationStateChangeListenerImplementor.java'。

在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.File.InternalDelete(字符串路径,布尔检查主机) 在 System.IO.File.Delete(字符串路径) 在 Xamarin.Android.Tools.Files.CopyIfStreamChanged(流流,字符串目标) 在 Xamarin.Android.Tasks.Generator.CreateJavaSources(TaskLoggingHelper 日志,IEnumerable`1 javaTypes,字符串 outputPath,字符串 applicationJavaClass,字符串 androidSdkPlatform,布尔 useSharedRuntime,布尔 generateOnCreateOverrides,布尔 hasExportReference)VidyoConnector.Android

对此有什么可能的解决方法?

【问题讨论】:

标签: c# xamarin xamarin.forms


【解决方案1】:

这似乎是 Windows 中长路径的问题。将项目文件夹放在根目录下,例如 C://yourproject。然后,清理您的解决方案并构建。

【讨论】:

    【解决方案2】:

    @LawrenceWlt 是正确的,但我想补充更多信息。

    是由于Maximum Path Length Limitation

    在 Windows API 中(下面将讨论一些例外情况 段落),路径的最大长度为 MAX_PATH,即 定义为 260 个字符。

    https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation

    https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation

    如果您使用的是 Windows 10 版本 1607 或更高版本,您可以启用长路径:

    注册表项Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD) 必须存在并设置为1。

    应用程序清单还必须包含 longPathAware 元素。

    <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
            <ws2:longPathAware>true</ws2:longPathAware>
        </windowsSettings>
    </application>
    

    https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation#enable-long-paths-in-windows-10-version-1607-and-later

    我在 Experimental Mobile Blazor Bindings 中遇到了类似的错误:

    https://github.com/xamarin/MobileBlazorBindings

    无法为类生成 Java 类型: Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor 由于 MAX_PATH: System.IO.DirectoryNotFoundException: 找不到 路径的一部分 'C:\Users\User\Desktop\MobileBlazorBindings-master\samples\MobileBlazorBindingsXaminals\MobileBlazorBindingsXaminals.Android\obj\Debug\90\android\src\mono\android\support\v4\view\accessibility\AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'。 在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径) 在 System.IO.File.InternalDelete(字符串路径,布尔检查主机)处 System.IO.File.Delete(字符串路径)在 Xamarin.Android.Tools.Files.CopyIfStreamChanged(流流,字符串 目的地)在 Xamarin.Android.Tasks.GenerateJavaStubs.CreateJavaSources(IEnumerable`1 javaTypes, TypeDefinitionCache 缓存)MobileBlazorBindingsXaminals.Android

    【讨论】:

      【解决方案3】:

      还有一个尚未提及的解决方案:创建一个 Directory Junction 并将其指向您的解决方案目录。将联结点放在根级别,然后从那里运行解决方案。

      这种方法将使您能够解决 MAX_PATH 问题,而无需移动您的项目或升级到 Windows 10。

      例如,假设您将所有代码存储在 C:\dev 中,所有存储库存储在 C:\dev\repos 中,所有 Git 存储库存储在 C:\dev\repos\git 中,所有 Xamarin Git 存储库存储在C:\dev\repos\git\xamarin,以及您在 C:\dev\repos\git\xamarin\isis 中为您最大的客户端构建的所有移动应用程序(嘿,这不是我评判的地方)。您的最新项目可以在 C:\dev\repos\git\xamarin\isis\satellite-tracker\src 中找到,但是由于路径太长,您无法构建它。

      因此,我们创建了一个新目录 C:\J,该目录将保存此结点以及我们为其他项目的此解决方法创建的任何其他结点。然后以管理员身份打开命令提示符并导航到 C:\J。然后输入以下命令:

      mklink /J SatTrack C:\dev\repos\git\xamarin\isis\satellite-tracker\src
      

      现在您可以从 C:\J\SatTrack 访问您的解决方案文件。如果从那里打开它,Visual Studio 将使用该路径而不是较长的路径,并且在清理/重建后应该没问题。

      【讨论】:

        【解决方案4】:

        一个很好的简单解决方案是更改 Android 项目 -> 属性 -> 构建 -> 输出路径中的构建输出文件夹

        【讨论】:

        • 这对我不起作用。
        【解决方案5】:

        将它添加到 Android 项目的 .csproj 文件为我解决了这个问题:

          <PropertyGroup>
            <IntermediateOutputPath>C:\E</IntermediateOutputPath>
          </PropertyGroup>
        

        它将中间 Android 文件写入您选择的文件夹 - 显然选择一个非常短的文件以避免长路径!

        【讨论】:

          猜你喜欢
          • 2020-01-19
          • 1970-01-01
          • 1970-01-01
          • 2018-08-16
          • 2020-01-10
          • 1970-01-01
          • 2017-12-05
          • 2021-01-28
          • 1970-01-01
          相关资源
          最近更新 更多