You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to bind an Android Library which is build using Data Binding #3853
@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.
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.
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.
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.
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.
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.
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.
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.
Activity
moljac commentedon Oct 29, 2019
@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
basheerkohli commentedon Oct 29, 2019
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.
paulzotov829 commentedon Jul 16, 2020
Hi Did you fix it?
moljac commentedon Jul 17, 2020
@paulzotov829
He did not fix it. We do not support that (yet).
4brunu commentedon Dec 8, 2020
Any news or plans on supporting DataBinding and ViewBinding?
moljac commentedon Dec 8, 2020
No. Not at the moment.
4brunu commentedon Jan 24, 2021
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.
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.
moljac commentedon Jan 24, 2021
WIP
dotnet/android-libraries#244
4brunu commentedon Jan 26, 2021
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
The solution I used was to remove the generated ViewBinding source from the public API by putting this in
Metadata.xmland it worked.@moljac thanks for your help 🙂
jeanraymonddaher commentedon Mar 9, 2021
Thank you for sharing @4brunu , it fixed my issue !
nielsdelporte commentedon Mar 17, 2021
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.Removing the
DataBinderMapperImplfrom the library in Metadata.xml doesn't yield any results either.Is there any update regarding this issue, @moljac ?
4brunu commentedon Mar 17, 2021
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.
nielsdelporte commentedon Mar 19, 2021
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.
Is Data Binding being worked on, since this ticket has requested support for Data Binding and closed?
Add NuGet packages for the return assistant feature to work