简体   繁体   English

如何修复Xamarin表单构建错误:“无法为类创建JavaTypeInfo”

[英]How to fix Xamarin forms build error: “Failed to create JavaTypeInfo for class”

On build, the compiler is throwing the following error: 在生成时,编译器将引发以下错误:

Error:- 错误:-

Severity Code Description Project File Line Suppression State Error Failed to create JavaTypeInfo for class: Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor due to System.IO.DirectoryNotFoundException: Could not find a part of the path '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.DirectoryNotFoundException,未能为以下类创建JavaTypeInfo:Android.Support.V4.View.Accessibility.AccessibilityManagerCompat / IAccessibilityStateChangeListenerImplementor:找不到路径'C:\\ Users的一部分\\ sHaRjAs \\ source \\ repos \\ FormsDatePickerFocusSample \\ FormsDatePickerFocusSample \\ FormsDatePickerFocusSample.Android \\ obj \\ Debug \\ 90 \\ android \\ src \\ mono \\ android \\ support \\ v4 \\ view \\ accessibility \\ Accessibility \\ AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'。 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs) ,字符串msgPath,布尔bFromProxy,布尔useLongPath,布尔checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at Xamarin.Android.Tools.Files.CopyIfStreamChanged(Stream stream, String destination) at Xamarin.Android.Tasks.Generator.CreateJavaSources(TaskLoggingHelper log, IEnumerable`1 javaTypes, String outputPath, String applicationJavaClass, String androidSdkPlatform, Boolean useSharedRuntime, Boolean generateOnCreateOverrides, Boolean hasExportReference) 在System.IO.FileStream..ctor(字符串路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize)在Xamarin.Android.Tools.Files.CopyIfStreamChanged(流流,String目标)在Xamarin.Android.Tasks.Generator .CreateJavaSources(TaskLoggingHelper日志,IEnumerable`1 javaTypes,字符串outputPath,字符串applicationJavaClass,字符串androidSdkPlatform,布尔值useSharedRuntime,布尔值generateOnCreateOverrides,布尔值hasExportReference)

XAML Code:- 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#:- 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();
        });
    }
    }
}

Have had a similar error just now. 刚才有类似的错误。 I found that it is connected to my VS solution name beeing kind of descriptive and long 我发现它已连接到我的VS解决方案名称,这是描述性且冗长的

WebApp_ReportGenerator_Framework_Dink_Oxy

If I created another project with something shorter for a solution and project name ( TestProj ), the android project built with no errors. 如果我创建了另一个项目,但解决方案和项目名称( TestProj )较短,则android项目不会出错。

@sHaRjAs: @sHaRjAs:
I guess the path to the java files in question (see error description) is too long because your project name is too long. 我猜有问题的Java文件的路径太长(请参阅错误描述),因为您的项目名称太长。 There are also other solutions than project renaming to solve this problem: Solutions here and here oficial . 除了项目重命名以外,还有其他解决方案可以解决此问题: 这里和此处的解决方案 ofofical

PS. PS。 If in xamarin forms one is using the 如果以xamarin形式使用

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

solution, note that "MyApp" folder in upper path is the folder containing all your forms projects : Android,UWP, IOs and standard API projects. 解决方案中,请注意,上方路径中的“ MyApp”文件夹是包含您所有表单项目的文件夹:Android,UWP,IO和标准API项目。 This is not clear in the docmentation, I think. 我认为这在文件中并不清楚。

For example if you put in the IntermediateOutputPath property the path to your android project, the Visual Studio locks and needs to be "endTasked". 例如,如果将IntermediateOutputPath属性放入android项目的路径,则Visual Studio会锁定,并且需要“ endTasked”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM