Bug 19904 - Public methods with Android @hide annotation are not acessible from C#/Xamarin.Android
Summary: Public methods with Android @hide annotation are not acessible from C#/Xamari...
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.12.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-05-19 13:56 UTC by Horácio J. C. Filho
Modified: 2014-05-20 08:22 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Horácio J. C. Filho 2014-05-19 13:56:00 UTC
Hello,

I have seen that public methods with Android @hide annotation from Android JDK are not accessible via C#/Xamarin.Android.

I will try to show the problem below.

This is a piece of LinkedHashMap class from https://android.googlesource.com/platform/libcore/+/refs/heads/master/luni/src/main/java/java/util/LinkedHashMap.java: 
/**
  * Returns the eldest entry in the map, or {@code null} if the map is empty.
  * @hide
  */
public Entry<K, V> eldest() {
  LinkedEntry<K, V> eldest = header.nxt;
  return eldest != header ? eldest : null;
}

The eldest method is not accessible directly, but it is possible access it using Java's Reflection API, but in Xamarin.Android, this method does not have its corresponding bind, therefore you can not access it using .Net's Reflection API. That leaves the code inconsistent, mixing Java API with .NET API. The ideal was that it could be done using only .NET's Reflection API, and not having to resort to Java.

I'm brazilian, sorry for my bad english :'(

Thanks a lot for attention. I love Xamarin.Android :D Long live for Xamarin o/
Comment 1 Jonathan Pryor 2014-05-19 15:52:05 UTC
> therefore you can not access it using .Net's Reflection API.

Unfortunately we haven't extended System.Reflection to be usable on Java members. (That would be an "interesting" thing to implement...)

You need to use Java reflection to access Java private members. You can do this either with Android.Runtime.JNIEnv, or you can use the bound Java.Lang.Reflect classes, in a nearly identical fashion as what would be done in Java.
Comment 2 Horácio J. C. Filho 2014-05-20 08:22:10 UTC
Thanks for answering me :D

I think that Java.Lang.Reflection is the best choice. I'll try to implement it and return the results to you.