Skip to content

MavenDownloadTask Advanced Scenarios

Jonathan Pobst edited this page Oct 6, 2022 · 1 revision

By default, <AndroidMavenLibrary> pulls from Maven Central. Here are some examples of other parameters that can be used to specify how to obtain the Java library and .pom.

Google's Maven

<ItemGroup>
  <AndroidMavenLibrary 
    Include="androidx.core:core" 
    Version="1.9.0" 
    Repository="Google" />
</ItemGroup>

Custom Maven

<ItemGroup>
  <AndroidMavenLibrary 
    Include="com.github.chrisbanes:PhotoView" 
    Version="2.3.0" 
    Repository="https://repository.mulesoft.org/nexus/content/repositories/public" />
</ItemGroup>

Note there is currently no support for Maven repositories that require authentication. A workaround is to procure the .jar/.aar and .pom externally and add them to your project as local files. (See next section.)

Local Files

<ItemGroup>
  <AndroidMavenLibrary 
    Include="my.company:package" 
    Version="1.0.0" 
    Repository="File"
    PackageFile="C:\packages\mypackage-1.0.0.jar"
    PomFile="C:\packages\mypackage-1.0.0.pom" />
</ItemGroup>

Note the .pom file must be specified in order to enable dependency checking. If you do not have a .pom file then a regular <AndroidLibrary> item can be used instead.

Binding and Packing

Like <AndroidLibrary>, <AndroidMavenLibrary> support the Bind and Pack attributes to determine if C# bindings should be generated and if the Java library should be included in the NuGet package, respectively. Both default to true.

<ItemGroup>
  <AndroidMavenLibrary 
    Include="androidx.core:core" 
    Version="1.9.0" 
    Repository="Google"
    Bind="false"
    Pack="false" />
</ItemGroup>