Jakub Holovsky Jakub Holovsky - 1 month ago 11
Android Question

Xamarin - .aar Java Binding - The name '[method name]' does not exist in the current context

I am trying to create binding for Facebook Notification .aar library.

However I am getting compile errors:

enter image description here


Severity Code Description Project File Line Suppression State
Error CS0103 The name 'CreateAsset' does not exist in the current
context FBNotifications C:\Users\jakub\documents\visual studio
2015\Projects\FBNotifications\FBNotifications\obj\Release\generated\src\Com.Facebook.Notifications.Internal.Asset.Handlers.BitmapAssetHandler.cs 344 Active

Severity Code Description Project File Line Suppression State
Error CS0103 The name 'CreateView' does not exist in the current
context FBNotifications C:\Users\jakub\documents\visual studio
2015\Projects\FBNotifications\FBNotifications\obj\Release\generated\src\Com.Facebook.Notifications.Internal.Asset.Handlers.BitmapAssetHandler.cs 350 Active


The methods that have the problem are following:

enter image description here

// This method is explicitly implemented as a member of an instantiated Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler
global::Java.Lang.Object global::Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler.CreateAsset (global::Org.Json.JSONObject p0, global::Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetCache p1)
{
return global::Java.Interop.JavaObjectExtensions.JavaCast<Java.Lang.Object>(CreateAsset (p0, p1));
}

// This method is explicitly implemented as a member of an instantiated Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler
global::Android.Views.View global::Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler.CreateView (global::Java.Lang.Object p0, global::Android.Content.Context p1)
{
return CreateView (global::Java.Interop.JavaObjectExtensions.JavaCast<global::Com.Facebook.Notifications.Internal.Asset.Handlers.BitmapAssetHandler.BitmapAsset>(p0), p1);
}


I can see that the code issue can be fixed like this:

// This method is explicitly implemented as a member of an instantiated Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler
global::Java.Lang.Object global::Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler.CreateAsset (global::Org.Json.JSONObject p0, global::Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetCache p1)
{
return global::Java.Interop.JavaObjectExtensions.JavaCast<Java.Lang.Object>(((AssetManager.IAssetHandler)this).CreateAsset (p0, p1));
}

// This method is explicitly implemented as a member of an instantiated Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler
global::Android.Views.View global::Com.Facebook.Notifications.Internal.Asset.AssetManager.IAssetHandler.CreateView (global::Java.Lang.Object p0, global::Android.Content.Context p1)
{
return ((AssetManager.IAssetHandler)this).CreateView (global::Java.Interop.JavaObjectExtensions.JavaCast<global::Com.Facebook.Notifications.Internal.Asset.Handlers.BitmapAssetHandler.BitmapAsset>(p0), p1);
}


I thought that creating a partial class for BitmapAssetHandler and putting there the corrected method while removing it in Metadata.xml would fix it but it doesn't seem like it.

<remove-node path="/api/package[@name='com.facebook.notifications.internal.asset.handlers']/class[@name='BitmapAssetHandler']/method[@name='CreateAsset']" />
<remove-node path="/api/package[@name='com.facebook.notifications.internal.asset.handlers']/class[@name='BitmapAssetHandler']/method[@name='CreateView']" />


If I do that then I get error that the methods exist twice (somehow they do not get removed from the generated code). I hope it's not too complex of a problem. Is my approach correct? Or is there something else needed to be done to be able to get it working.

Answer

remove-node element does the trick.

<remove-node path="/api/package[@name='com.facebook.notifications.internal.asset.handlers']/class[@name='BitmapAssetHandler']" />
Comments