【问题标题】:How to fix Xamarin forms build error: “Failed to create JavaTypeInfo for class”如何修复 Xamarin 表单构建错误:“无法为类创建 JavaTypeInfo”
【发布时间】:2020-01-19 11:59:24
【问题描述】:

在构建时,编译器抛出以下错误:

错误:-

严重性代码描述项目文件行抑制状态 错误无法为类创建 JavaTypeInfo: Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor 由于 System.IO.DirectoryNotFoundException: 找不到一部分 路径 'C:\Users\sHaRjAs\source\repos\FormsDatePickerFocusSample\FormsDatePickerFocusSample\FormsDatePickerFocusSample.Android\obj\Debug\90\android\src\mono\android\support\v4\view\accessibility\AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'。 在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess 访问、Int32 权限、布尔用户权限、FileShare 共享、Int32 bufferSize,FileOptions 选项,SECURITY_ATTRIBUTES secAttrs,字符串 msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
在 System.IO.FileStream..ctor(字符串路径,FileMode 模式,FileAccess 访问,文件共享共享,Int32 bufferSize)在 Xamarin.Android.Tools.Files.CopyIfStreamChanged(流流,字符串 目的地)在 Xamarin.Android.Tasks.Generator.CreateJavaSources(TaskLoggingHelper 日志,IEnumerable`1 javaTypes,字符串输出路径,字符串 applicationJavaClass, String androidSdkPlatform, Boolean useSharedRuntime, Boolean generateOnCreateOverrides, Boolean hasExportReference)

XAML 代码:-

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:FormsDatePickerFocusSample"
             x:Class="FormsDatePickerFocusSample.MainPage">

    <StackLayout VerticalOptions="CenterAndExpand"
                     HorizontalOptions="CenterAndExpand"
                     BackgroundColor="White">

        <Button x:Name="MyButton"
                    Text="Show DatePicker"
                    Clicked="OnMyButtonClicked"/>

        <DatePicker x:Name="MyDatePicker"
                        IsVisible="False"/>

    </StackLayout>

</ContentPage>

c#:-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace FormsDatePickerFocusSample
{
// Learn more about making custom code visible in the Xamarin.Forms 
previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }
    private void OnMyButtonClicked(object sender, EventArgs e)
    {
        Device.BeginInvokeOnMainThread(() =>
        {
            if (MyDatePicker.IsFocused)
                MyDatePicker.Unfocus();

            MyDatePicker.Focus();
        });
    }
    }
}

【问题讨论】:

  • 我使用相同的代码进行测试。没有错误。您可以尝试清理并重建此项目或删除此项目的 bin 和 obj 文件数据重试。如果您仍然收到此编译器错误,快速的方法是创建一个新项目以使用代码进行测试。
  • @WendyZang 它不起作用(Soln 未更改)
  • 我在GitHub上上传了我的测试项目,你可以下载测试。 github.com/WendyZang/Test如果还有错误,能否分享更多代码供我测试?
  • 有什么更新吗?你的问题解决了吗?

标签: c# xamarin xamarin.forms


【解决方案1】:

刚才遇到了类似的错误。我发现它连接到我的 VS 解决方案名称,因为它具有描述性且冗长

WebApp_ReportGenerator_Framework_Dink_Oxy

如果我用更短的解决方案和项目名称 (TestProj) 创建了另一个项目,则构建的 android 项目没有错误。

@sHaRjAs:
我猜有问题的 java 文件的路径(请参阅错误描述)太长,因为您的项目名称太长。除了项目重命名之外,还有其他解决方案可以解决此问题:Solutions here 和这里oficial

附言。如果在 xamarin 形式中使用的是

<PropertyGroup> <IntermediateOutputPath>C:\Projects\MyApp</IntermediateOutputPath> </PropertyGroup>

解决方案,请注意上方路径中的“MyApp”文件夹是包含所有表单项目的文件夹:Android、UWP、IO 和标准 API 项目。我认为这在文档中并不清楚。

例如,如果您在 IntermediateOutputPath 属性中输入 android 项目的路径,Visual Studio 会锁定并需要“endTasked”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2020-12-07
    • 2023-01-04
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多