构建xamarin android项目不成功,错误XA4212

Liu*_*eng 13 android xamarin.android

在Visual Studio 2017 15.4中,一切都很顺利.但是在我升级到15.5之后,我的xamarin android项目无法成功构建,显示:

error XA4212: Type `Android.Support.V4.App.JobIntentService/JobServiceEngineImpl` implements `Android.Runtime.IJavaObject` but does not inherit `Java.Lang.Object` or `Java.Lang.Throwable`. This is not supported.
Run Code Online (Sandbox Code Playgroud)

Car*_*487 29

在@Ironman回答之后,这发生在Xamarin.Android 8.0中,所以我在以下部分的项目.csproj文件中将属性设置为false.

<PropertyGroup>
    <!-- Other properties -->
    <AndroidErrorOnCustomJavaObject>false</AndroidErrorOnCustomJavaObject>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

在大多数情况下,您应该添加属性,因为默认情况下它不存在.

现在,您可以正常构建和运行应用程序,只有警告.

请注意.csproj文件中的其他PropertyGroup标记,这些标记特定于构建条件.

您可以在https://github.com/xamarin/xamarin-android/blob/master/Documentation/build_process.md中查看其他构建属性和配置.


Har*_*iya 0

AndroidErrorOnCustomJavaObject :

一个布尔属性,用于确定类型是否可以 Android.Runtime.IJavaObject在不继承 Java.Lang.Object或的情况下实现Java.Lang.Throwable

class BadType : IJavaObject {
    public IntPtr Handle {
        get {return IntPtr.Zero;}
    }

    public void Dispose()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

当为 True 时,此类类型将生成 XA4212 错误,否则将生成 XA4212 警告。

Xamarin.Android 8.1 中添加了对此属性的支持。

该属性默认为 True。