Search code examples
c#androidxamarinxamarin-studioaar

How to add AAR library to xamarin studio?


Is there any possibilty to add aar library to xamarin studio? I use xamarin studio on mac and i tried add project based on gradle - caldroid to my project. When i try add aar lib to my project with ProjectLibraryZip properties. I can not use any method from this library i c#


Solution

  • You would need to add a Java Bindings Library (via Xamarin.Android Java Bindings Library template) to your Xamarin solution and add the .aar file to the Jar folder in the project tree (Embedded Jar Build Action) just as you would a .jar file.

    That was the easy part, now simply compiling that Library project will cause the generation of a C# wrapper for ALL the classes/methods/enums/consts in that Jar/Aar file. It usually is never just that simple as not everything translates cleanly from Java to C# so be prepared to manually write some transformation rules to filter out classes, rename methods, etc.. that are located in the project tree at:

    ├── Transforms
    │   ├── EnumFields.xml
    │   ├── EnumMethods.xml
    │   └── Metadata.xml
    

    Xamarin has a good walk through of the entire process, start there: