Hello! 👋
The last article I wrote was about creating CalendarView with .NET MAUI Handler. For Android, I used Android.Widget.CalendarView
. Unfortunately it doesn't have a material design and luck of some features. There is another library com.applandeo:material-calendar-view
, but it is a Java library. We need to create a bindings library. Today I want to show you how to easily create an Android library binding.
Getting Started
Create a new .NET Android Bindings library either through the VS "New Project" dialog or the command line:
Add the XamPrototype.Android.MavenBinding.Tasks
NuGet package to the library through VS or the command line:
This package allows Java libraries to be bound directly from Maven repositories. It also provides a task to verify that all required Java dependencies are being fulfilled.
This feature focuses on tackling two pain points of binding from Maven:
Acquiring the
.jar
/.aar
and the related.pom
from MavenUsing the
.pom
to verify that required Java dependencies are being fulfilled
Let's take an example: com.applandeo:material-calendar-view
version 1.9.0
available in Maven.
Add a new <AndroidMavenLibrary>
which specifies the Java artifact we want to bind:
Note: By default, this pulls the library from Maven Central. There is also support for Google's Maven, custom Maven repositories, and local Java artifact files. See Advanced MavenDownloadTask Usage for more details.
If you compile the binding now, the library will be automatically downloaded from Maven as well as the associated .pom
file. The .pom
file details the dependencies needed by this library, and the build errors will be generated:
To fix such an error we can add suggested NuGet packages:
If some bindings are not available in NuGet, we can add them manually from Maven without binding:
Note: Not all dependencies will have official NuGet bindings. For other examples of ways to fulfill dependencies, see Advanced MavenDependencyVerifierTask Scenarios.
Now if you try to compile the library the dependencies will be detected as fulfilled, and the build continues. If you get C# compile errors (like with this package) you are now back to the normal binding process. (ie: fixing with Metadata).
Conclusion
That's it! You can now easily create Android library bindings.
The full code can be found on GitHub.
Happy Bindings!