Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Problem with companion objects binding library for Android.

ant04xant04x Member ✭✭

Hello, I'm a little bit frustrated :'( , I can't access to a Kotlin's companion object method for create a component that has not visible constructors. The binding library generates a Component.Companion with the Make() method for create the component, but the Component class has not a instance of it, the Companion has not a visible contructor too and the Make() method is not static.

So, what would be the correct solution for that specific problem? I will be eternally grateful if you find the answer that rescues my end-of-grade work. o:)


  • JarvanJarvan Member, Xamarin Team Xamurai

    Try checking the related troubleshooting guides to get the cause to the issue:

    The following guide has an outline on approaching a binding as well as some troubleshooting:
    This doc summarizes serveral common errors that may occur when generating bindings:

  • ant04xant04x Member ✭✭

    Thank you so much for your answer.

    I already study all the documentation for Kotlin and Java binding libraries. My problem seems a version error between the Kotlin library and the Xamarin project.But there is only one thing that I'm not sure, the Kotlin version, in the documentation specifies the 1.3.10 (I cannot use it because is deprecated) and in a image attached below uses the version 1.3.50.

    I don't know what I'm gonna do. :'(

  • JarvanJarvan Member, Xamarin Team Xamurai

    the Kotlin version, in the documentation specifies the 1.3.10 ... and in a image attached below uses the version 1.3.50.

    This may be because the doc is not updated in time. You could refer to the official sample code which is updated several days ago, the native Kotlin version of the sample is 1.4.0.

    Sample code links:

  • ant04xant04x Member ✭✭

    Nothing, the constructor block is still there with everything migrated to Kotlin 1.4.0 :/

    The error would be solved if the Metadata could add a constructor or create a static instance of the generated class Companion... But it's not possible, is it?

    I don't know what I'm going to do :'(

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 26

    Does the Kotlin library contain the constructor method? If the type missed after binding, check the similar problem:

  • ant04xant04x Member ✭✭

    Nothing has been missed. The Snackbar.Companion class is generated to repace de companion object {...} of Kotlin, it has sense, but I can't access to the method that is inside called public Snackbar make() {...} because the Companion class it has only the constructor internal Companion(IntPtr javaReference, JniHandleOwnership transfer) that is unaccessible by its visibility level.

    Now, can I change the visibility level of this constructor? :/
    I tried this but it doesn't work:

    <attr path="/api/package[@name='']/class[@name='Snackbar.Companion']/constructor[@name='Companion' and count(parameter)=2 and parameter[1][@name='system.IntPtr'] and parameter[2][@type='android.runtime.JniHandleOwnership']]" name="visibility">public</attr>

    I'm desperate. :s

Sign In or Register to comment.