Skip to content

How to bind an Android Library which is build using Data Binding #3853

Closed

Description

@basheerkohli

Steps to Reproduce

  1. Create Android Library with data binding enabled using android studio.
  2. Now try to create DLL for the android library using visual studio.
  3. Build process is success. But you won't find classes relating to the Data Binding.
  4. In the Build logs you will find a warning
    [ noClassDefFoundError: Landroidx/databinding/DataBinderMapperImpl ]

Expected Behavior

Actual Behavior

Version Information

Log File

Activity

  1. moljac commented on Oct 29, 2019

    @moljac
    Contributor

    @basheerkohli
    Databinding in Android (Android.Studio) relies on gradle plugin[s] what would map to MSBuild Tasks, Targets and of course Custom Tasks. This is a lot and needs resources (analysis, design and coding-implementation)

    Thus we did not bind Databinding group (and artifacts).

    We redirect people to use Xamarin (XAML) databindings infrastructure. I know this is Xamarin.Android not Xamarin.Forms.

    If you want we can discuss it. If you are willing to do some research (what gradle plugins do) and analysis it may turn out that effort is not too big.

    But, NO PROMISES from our side

  2. basheerkohli commented on Oct 29, 2019

    @basheerkohli
    Author

    Hard to take that from you. But again thank you for your quick response @moljac . I have generated an SDK in native with data binding enabled. What you have said is correct as data binding relies on Gradle plugin[s] & has no issues while consuming the SDK from React Native, Ionic frameworks. But unfortunately, in this case, I have to think of the alternative of replacing Data binding with old school view reference objects. Thank you for the quick response. Cheers.

  3. paulzotov829 commented on Jul 16, 2020

    @paulzotov829

    Hi Did you fix it?

  4. moljac commented on Jul 17, 2020

    @moljac
    Contributor

    @paulzotov829

    He did not fix it. We do not support that (yet).

  5. 4brunu commented on Dec 8, 2020

    @4brunu

    Any news or plans on supporting DataBinding and ViewBinding?

  6. moljac commented on Dec 8, 2020

    @moljac
    Contributor

    No. Not at the moment.

  7. 4brunu commented on Jan 24, 2021

    @4brunu

    For those interested in this issue, I leave here some info, of some research and experimentations regarding binding Android Libraries that use DataBinding or ViewBinding.

    To bind an Android library that uses ViewBinding is very easy.
    The only thing we have to do is add the dependency androidx.databinding:viewbinding, and it just works.
    I already create an issue, asking for the bind of this dependency dotnet/android-libraries#243.

    To bind an Android Library that uses DataBinding it's not so easy.
    I tried to add the dependencies of DataBinding, but it didn't work.

    implementation 'androidx.databinding:databinding-common:4.1.2'
    implementation 'androidx.databinding:databinding-runtime:4.1.2'
    implementation 'androidx.databinding:databinding-adapters:4.1.2'
    

    It requires the DataBinding gradle plugin and annotation processing to be enable on the consumer side, otherwise it throws the error [ noClassDefFoundError: Landroidx/databinding/DataBinderMapperImpl ]
    So supporting DataBinding will required a lot more work and investigation.

    For now I will be happy with the support for ViewBinding, since it's easy to support, google it's pushing it, it's becoming more popular and widely used.

  8. moljac commented on Jan 24, 2021

    @moljac
    Contributor
  9. 4brunu commented on Jan 26, 2021

    @4brunu

    I'm leaving here this extra information in case it helps anyone.
    Now that https://www.nuget.org/packages/Xamarin.AndroidX.DataBinding.ViewBinding/ is already published on NuGet, I was able to bind an Android library the uses View Binding.

    In the begining I was havving the following error

    Error CS0738: 'ActivityTimeBinding' does not implement interface member 'IViewBinding.Root'. 
    'ActivityTimeBinding.Root' cannot implement 'IViewBinding.Root' because it does not have the matching return type of 'View'. (CS0738)
    

    The solution I used was to remove the generated ViewBinding source from the public API by putting this in Metadata.xml and it worked.

        <remove-node path="/api/package[@name='com.example.mylibrary.databinding']" /> 
    

    @moljac thanks for your help 🙂

  10. jeanraymonddaher commented on Mar 9, 2021

    @jeanraymonddaher

    Thank you for sharing @4brunu , it fixed my issue !

  11. nielsdelporte commented on Mar 17, 2021

    @nielsdelporte

    We're also seeing the [ noClassDefFoundError: Landroidx/databinding/DataBinderMapperImpl ] error when adding the following nuget packages to our main project. Adding the same packages to the bindings project for our native library did not make a difference.

    <package id="Xamarin.AndroidX.DataBinding.DataBindingAdapters" version="4.1.2.1" targetFramework="monoandroid10.0" />
    <package id="Xamarin.AndroidX.DataBinding.DataBindingCommon" version="4.1.2.1" targetFramework="monoandroid10.0" />
    <package id="Xamarin.AndroidX.DataBinding.DataBindingRuntime" version="4.1.2.1" targetFramework="monoandroid10.0" />
    <package id="Xamarin.AndroidX.DataBinding.ViewBinding" version="4.1.2.1" targetFramework="monoandroid10.0" />
    

    Removing the DataBinderMapperImpl from the library in Metadata.xml doesn't yield any results either.

        <remove-node path="/api/package[@name='com.example.databinding']" /> 
        <remove-node path="/api/package[@name='com.example']/class[@name='BR']" />
        <remove-node path="/api/package[@name='com.example']/class[@name='DataBinderMapperImpl']" />
    
    

    Is there any update regarding this issue, @moljac ?

  12. 4brunu commented on Mar 17, 2021

    @4brunu

    The problem is that the library that you are trying to use, uses DataBinding, which is not supported in Xamarin binding, AFAIK, only ViewBinding is supported.

  13. nielsdelporte commented on Mar 19, 2021

    @nielsdelporte

    Thanks, @4brunu! We dropped DataBinding and will only use ViewBinding for now, which is a big step forward already.
    We only needed one NuGet binding in our main project and no Metadata.xml entries.

    <package id="Xamarin.AndroidX.DataBinding.ViewBinding" version="4.1.2.1" targetFramework="monoandroid10.0" />
    

    Is Data Binding being worked on, since this ticket has requested support for Data Binding and closed?

  14. ghost locked as resolved and limited conversation to collaborators on Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: BindingsIssues in Java Library Binding projects.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions