未在路径中找到 class“android.support.constraint.ConstraintLayout”:Xamarin.Android 中的 DexPathList

Didn’t find class “android.support.constraint.ConstraintLayout” on path: DexPathList in Xamarin.Android

我有一个非常简单的 xamarin 经典应用程序,带有以下 .axml 文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Hello World!"/>
</android.support.constraint.ConstraintLayout>

及以下 .cs 文件

[Activity(Label = "sa", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.Main);//error throws here
    }
}

我找到了 .gradle 的下一个代码以启用约束布局

dependencies {
              compile 'com.android.support.constraint:constraint-layout:1.0.2'
           }

但是,当然,它在 Xamarin.Android 中不起作用。我试着安装 Xamarin Android Constraint Layout 1.0.0-beta5

但它不适用于 Mono.Android 6.0.

我该如何解决我的问题?有什么猜测吗?

class android.support.constraint.ConstraintLayout 由于某种原因没有进入 dex 列表。

一些原因可能是:

  • 未安装
  • 正在链接出去
  • 它不会生成主 dex 列表,而只会生成辅助 dex 列表。

使用 Classy Shark 确定发生了什么(https://github.com/google/android-classyshark)。确保您的链接器设置设置为 None 以确保 Mono 链接器也不会删除它。

我只需要更改 mono 框架版本即可 android.csproj v7.0

我最近(实际上是今天)运行 解决了这个问题,我已经能够通过在我的 linker settings

中添加一个例外来解决
<assembly fullname="Xamarin.Android.Support.Constraint.Layout">
  <type fullname="*" />
</assembly>

<assembly fullname="Xamarin.Android.Support.Constraint.Layout.Solver">
  <type fullname="*" />
</assembly>

显然,相应的 class 已被链接(正如 Jon Douglas 所建议的)。通过添加此例外,您可以防止 class 被链接。