XDev.Android.MavenBinding.Tasks
0.0.14.1
dotnet add package XDev.Android.MavenBinding.Tasks --version 0.0.14.1
NuGet\Install-Package XDev.Android.MavenBinding.Tasks -Version 0.0.14.1
<PackageReference Include="XDev.Android.MavenBinding.Tasks" Version="0.0.14.1" />
paket add XDev.Android.MavenBinding.Tasks --version 0.0.14.1
#r "nuget: XDev.Android.MavenBinding.Tasks, 0.0.14.1"
// Install XDev.Android.MavenBinding.Tasks as a Cake Addin #addin nuget:?package=XDev.Android.MavenBinding.Tasks&version=0.0.14.1 // Install XDev.Android.MavenBinding.Tasks as a Cake Tool #tool nuget:?package=XDev.Android.MavenBinding.Tasks&version=0.0.14.1
Fork info
This package is a fork of the original to add support for multiple native libs (.jar's or .aar's) being supplied by a "roll-up" package and resolved by consuming projects using this forked build-task package.
Currently, there is no support for defining multiple native artifacts in a consuming project's <PackageReference>
or in <ProjectReference>
nodes as discussed/proposed in .Net 9 preview.
See here for discussion on possible inclusion of "roll-up" packages in .Net 9, and express your support/interest.
Extended features in this fork
This fork depends on the NuGet package(s) containing multiple native artifacts to list them in the package Metadata tags separated by ";" like:
<PackageTags>
square;moshi;moshi-adapters;java;android;
artifact=com.squareup.moshi:moshi;artifact_versioned=com.squareup.moshi:moshi:1.15.0;
artifact=com.squareup.moshi:moshi-adapters;artifact_versioned=com.squareup.moshi:moshi-adapters:1.15.0;
</PackageTags>
All other original functionality is un-changed in this fork.
If you'd like to extend this fork (like adding support for defining multiple refs in <PackageReference JavaArtifact="">
), please contribute!
Notes on usage
When adding or updating the
XDev.Android.MavenBinding.tasks
package, it is recommended to reload the project, and this can be a little slow.Using this package along side the original
XamPrototype.Android.MavenBinding.Tasks
in a single solution is not supported and behavior is undefined.It is recommended to make this package private (the original too) in the consuming project so that this package does not propagate as a NuGet dependency itself. It is only an optional build-tool, not a runtime dependency, like so:
<PackageReference Include="XDev.Android.MavenBinding.Tasks" Version="x.y.z" PrivateAssets="All"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference>
Update
NOTE: Versions of these features have been added to .NET 9 Preview 3 and thus there will not be any future updates to this repository.
Original Content
We are prototyping a new feature for .NET for Android 8 that allows Java libraries to be bound directly from Maven repositories. Additionally, it uses the .pom
file provided to ensure that the dependencies needed by the Java library are met.
In order to get early testing and feedback, we are shipping a preview of this as a NuGet package that can be used from .NET 6/7.
Note this is a proposed new .NET for Android 8 feature. There is no guarantee that it will ship in the final .NET 8.
This feature focuses on tackling two pain points of binding from Maven:
- Acquiring the
.jar
/.aar
and the related.pom
from Maven - Using the
.pom
to verify that required Java dependencies are being fulfilled
Getting Started
Create a new .NET Android Bindings library either through the VS "New Project" dialog or the command line:
dotnet new androidlib
Add the XamPrototype.Android.MavenBinding.Tasks
NuGet package to the library through VS or the command line:
dotnet add package XamPrototype.Android.MavenBinding.Tasks
Let's take an example: Square's okhttp3
version 4.9.3
available in Maven.
Editor's note: we have an official binding for this library, but for the sake of an example.
Add a new <AndroidMavenLibrary>
which specifies the Java artifact we want to bind:
<ItemGroup>
<AndroidMavenLibrary Include="com.squareup.okhttp3:okhttp" Version="4.9.3" />
</ItemGroup>
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 following build errors will be generated:
error XA0000: Maven dependency 'com.squareup.okio:okio' version '2.8.0' is not satisfied. Microsoft maintains the NuGet package 'Square.OkIO' that could fulfill this dependency.
error XA0000: Maven dependency 'org.jetbrains.kotlin:kotlin-stdlib' version '1.4.10' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.Kotlin.StdLib' that could fulfill this dependency.
These are both libraries that Microsoft provides official NuGet bindings for, so we can add those NuGet packages:
dotnet add package Xamarin.Kotlin.StdLib
dotnet add package Square.OkIO
Note: Not all dependencies will have official NuGet bindings. For other examples of ways to fulfill dependencies, see Advanced MavenDependencyVerifierTask Scenarios.
Note: We still need to get the required metadata into all of our packaged bindings. If you still get resolution errors then we haven't added it to these packages. You will need to add the following attributes as described in see Advanced MavenDependencyVerifierTask Scenarios. In the future it will work automagically.
<PackageReference Include="Square.OkIO" Version="2.10.0.5" JavaArtifact="com.squareup.okio:okio" JavaVersion="2.10.0" />
<PackageReference Include="Xamarin.Kotlin.StdLib" Version="1.7.10" JavaArtifact="org.jetbrains.kotlin:kotlin-stdlib" JavaVersion="1.7.10" />
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).
Known Limitations
- Several of Microsoft's published NuGet bindings are missing needed metadata for automatic dependency resolution. Will be audited and fixed. (Workaround)
Feedback
If you give this a try, we'd love to hear your feedback! Did it work? Are there any additional scenarios that we should explore covering?
Please use the Discussions
tab on this GitHub repo for feedback, or the Issues
tab for bugs.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Extending support of original package to support "roll-up" packages when artifacts listed in package tags (meta-data).
- Updated dependencies that have vulnerabilities.
- Removed some debug output in build logs
- Fixed issue where IgnoredMavenDependency tag was not respected. https://xdevapps.visualstudio.com/Android bindings/_boards/board/t/Android bindings Team/Issues?workitem=129