我有一个使用Android库的Android应用程序(Java)。 一切正常,但我需要将此应用程序包装到Xamarin应用程序中。所以我决定将这个应用程序转换为第二个Android库。 我创建了我的Xamarin Android应用程序和一个Android Java Bindings Library项目,其中我将两个.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);
}
}
确实,&#34; id_delegate&#34;重复..
我也有类似于第一个.aar(不是应用程序)的警告:
/../JARTOXML: Warning J2X9001: Couldn't load class com/company/project/controllers/activities/MenuActivity : java.lang.NoClassDefFoundError: android/support/v4/app/FragmentActivity (J2X9001)
答案 0 :(得分:1)
好的,我通过向Metadata.xml添加remove-node语句解决了第一部分错误。
对于第二部分,添加对Xamarin.Android.Support.v4的引用解决了这个问题。