25

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?

Snostorp
  • 544
  • 1
  • 8
  • 14
Alexey K
  • 6,537
  • 18
  • 60
  • 118

4 Answers4

20

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.

jzeferino
  • 7,700
  • 1
  • 39
  • 59
  • 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 – Skye Hoefling Oct 26 '17 at 03:09
  • 1
    @AndrewHoefling the plugin is being maintained and it seems to be working as you said, here isto the [github](https://github.com/EgorBo/Xamarin.GradleBindings) repo. – jzeferino Oct 26 '17 at 08:46
  • @AndrewHoefling i came across same issue where library doesn't convert to c#. How you handle this issue, please elaborate? – Aniket Dec 07 '18 at 14:23
  • @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](https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/troubleshooting-bindings) 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. – Skye Hoefling Jan 04 '19 at 15:03
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/

Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68
  • This will work for C++ projects using the Android NDK, but the OP was asking about Xamarin (C#). – jeyoor Jul 19 '18 at 13:48
  • 1
    It works for Gradle projects that are part of a Xamarin app. Bind the resulting AAR with an Android Binding library, that's all. – user1725145 Sep 17 '19 at 13:49
1

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

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
0

Typically you won't use gradle to build your Xamarin projects. Thus you need to integrate/ reference those libraries through NuGet packages. AppCompat and Support Design are both available as NuGet packages. The otherone, if it does what I think it does, won't be needed because c# as build in async-support.

tequila slammer
  • 2,821
  • 1
  • 18
  • 25
  • 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 ? – Alexey K Jun 27 '16 at 09:04