Xamarin java 绑定库编译器错误

Xamarin java binding library compiler error

我有一个使用 Android 库的 android 应用程序 (Java)。 一切正常,但我需要将此应用程序包装到 Xamarin 应用程序中。所以我决定将此应用程序转换为第二个 Android 库。 我创建了我的 Xamarin Android 应用程序和一个 Android Java 绑定库项目,我在其中将两个 .aar 文件添加到 "Jars" 文件夹。

当我尝试编译这个绑定项目时,问题来了。我收到很多这样的错误:

/.../obj/Release/generated/src/Com.Google.Common.Util.Concurrent.ForwardingListenableFuture.cs(17,17): Error CS0102: The type `Com.Google.Common.Util.Concurrent.ForwardingListenableFutureInvoker' already contains a definition for `id_delegate' (CS0102)

当我打开生成的 ForwardingListenableFuture.cs 文件时,会出现以下代码:

[global::Android.Runtime.Register ("com/google/common/util/concurrent/ForwardingListenableFuture", DoNotGenerateAcw=true)]
internal partial class ForwardingListenableFutureInvoker : ForwardingListenableFuture, global::Com.Google.Common.Util.Concurrent.IListenableFuture {

        public ForwardingListenableFutureInvoker (IntPtr handle, JniHandleOwnership transfer) : base (handle, transfer) {}

        protected override global::System.Type ThresholdType {
            get { return typeof (ForwardingListenableFutureInvoker); }
        }

        static IntPtr id_delegate;
        // Metadata.xml XPath method reference: path="/api/package[@name='com.google.common.util.concurrent']/class[@name='ForwardingListenableFuture']/method[@name='delegate' and count(parameter)=0]"
        [Register ("delegate", "()Lcom/google/common/util/concurrent/ListenableFuture;", "GetDelegateHandler")]
        protected override global::Com.Google.Common.Util.Concurrent.IListenableFuture Delegate ()
        {
            if (id_delegate == IntPtr.Zero)
                id_delegate = JNIEnv.GetMethodID (class_ref, "delegate", "()Lcom/google/common/util/concurrent/ListenableFuture;");
            return global::Java.Lang.Object.GetObject<global::Com.Google.Common.Util.Concurrent.IListenableFuture> (JNIEnv.CallObjectMethod  (Handle, id_delegate), JniHandleOwnership.TransferLocalRef);
        }

        static IntPtr id_delegate;
        // Metadata.xml XPath method reference: path="/api/package[@name='com.google.common.util.concurrent']/class[@name='ForwardingFuture']/method[@name='delegate' and count(parameter)=0]"
        [Register ("delegate", "()Ljava/util/concurrent/Future;", "GetDelegateHandler")]
        protected override global::Java.Util.Concurrent.IFuture Delegate ()
        {
            if (id_delegate == IntPtr.Zero)
                id_delegate = JNIEnv.GetMethodID (class_ref, "delegate", "()Ljava/util/concurrent/Future;");
            return global::Java.Lang.Object.GetObject<global::Java.Util.Concurrent.IFuture> (JNIEnv.CallObjectMethod  (Handle, id_delegate), JniHandleOwnership.TransferLocalRef);
        }

        static IntPtr id_delegate;
        // Metadata.xml XPath method reference: path="/api/package[@name='com.google.common.collect']/class[@name='ForwardingObject']/method[@name='delegate' and count(parameter)=0]"
        [Register ("delegate", "()Ljava/lang/Object;", "GetDelegateHandler")]
        protected override global::Java.Lang.Object Delegate ()
        {
            if (id_delegate == IntPtr.Zero)
                id_delegate = JNIEnv.GetMethodID (class_ref, "delegate", "()Ljava/lang/Object;");
            return global::Java.Lang.Object.GetObject<global::Java.Lang.Object> (JNIEnv.CallObjectMethod  (Handle, id_delegate), JniHandleOwnership.TransferLocalRef);
        }

    }

的确,"id_delegate" 是重复的..

我也有与第一个 .aar(不是应用程序)相关的警告:

/../JARTOXML: Warning J2X9001: Couldn't load class com/company/project/controllers/activities/MenuActivity : java.lang.NoClassDefFoundError: android/support/v4/app/FragmentActivity (J2X9001)

好的,我通过向 Metadata.xml.

添加 remove-node 语句解决了错误的第一部分

对于第二部分,添加对 Xamarin.Android.Support.v4 的引用解决了问题。