Gradle dependencies in Xamarin

25,426

Solution 1

There is no gradle in Xamarin.Android.

To get external libraries or Android libraries you could use:

  1. NuGet

  2. Xamarin Components

  3. Do your own Java Library binding

  4. Convert code directly from Java to C#.

  5. There is a plugin for Visual Studio (tested it a few months ago but didn't worked for me) that in theory grabs dependencies from gradle and tries to convert them to C# Bindings.

Here you have a very good github page with awesome Xamarin Plugins.

Solution 2

Build your Android applications in Visual Studio using Gradle.

With the latest Visual Studio release, if you take a look at the cross-platform C++ section in the File->New project template section, you will see a variety of templates as shown in the figure below. Notice two new Gradle templates that have been introduced.

Source: https://blogs.msdn.microsoft.com/vcblog/2016/06/12/build-your-android-applications-in-visual-studio-using-gradle/

Solution 3

You can try the Java library binding, it's basically creating a C# binding Java library to consume your library from your Xamarin project.

Share:
25,426

Related videos on Youtube

Alexey K
Author by

Alexey K

Updated on June 12, 2020

Comments

  • Alexey K
    Alexey K almost 4 years

    Is it possible to integrate dependencies from Gradle inside Xamarin project?

    A have some libraries, which I need to install, they look like this

    dependencies {
    compile (name: '<aar fileName>', ext:'aar')
    compile 'com.koushikdutta.async:androidasync:2.1.6'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0' compile
    }
    

    Can I expose them to Xamarin somehow?

  • Alexey K
    Alexey K almost 8 years
    Thanks! But there are some more, and Im not sure, that they exist in Xamarin, because they are from 3rd party framework provider. Is there a way to integrate those libraries in xamarin project ?
  • Skye Hoefling
    Skye Hoefling over 6 years
    I strongly recommend using that Gradle Plugin for Visual Studio if you want to use a Gradle Java Dependency. It can be a real pain in the butt to get it all working but it will work. If you run into issues you can specify ignores so you only expose what you need from the java library. I have ran into issues where the library doesn't convert to C# nicely and I had to specify the ignores to get it working
  • jzeferino
    jzeferino over 6 years
    @AndrewHoefling the plugin is being maintained and it seems to be working as you said, here isto the github repo.
  • jeyoor
    jeyoor almost 6 years
    This will work for C++ projects using the Android NDK, but the OP was asking about Xamarin (C#).
  • Aniket
    Aniket over 5 years
    @AndrewHoefling i came across same issue where library doesn't convert to c#. How you handle this issue, please elaborate?
  • Skye Hoefling
    Skye Hoefling over 5 years
    @Aniket it could be caused by a 100 different things. I would start by taking a look at the official Xamarin documentation on how Java Bindings work. They have a troubleshooting guide that should be helpful. The extension that I mentioned is just a wrapper for the official support by Xamarin. My guess is there are name conflicts when it trys to port the java to C#. I would start by only exposing the objects you need.
  • user1725145
    user1725145 over 4 years
    It works for Gradle projects that are part of a Xamarin app. Bind the resulting AAR with an Android Binding library, that's all.