Search code examples
androidionic-frameworkcapacitoraar

How to use an android library (.aar file) in Ionic with Capacitor


I need to use a library from an android device, that was passed to me in an aar file, in a project with Ionic and I can't integrate it. Searching all I find is that it should make a Cordova plugin but I am using Capacitor.

I need to be able to integrate it into the project and use it with typescript.


Solution

  • If someone has the same problem, what I did was create a Capacitor plugin using the command npm init @capacitor/plugin.

    The issue was that there was an error when including the .aar library within the plugin, as it compiles as an .aar library on its own.

    You have to place the .aar library inside /android/libs of both the plugin and the project, and in the plugin's build.gradle file, add it as compileOnly files('libs/[lib_name].aar') instead of an implementation.