Add aar file to cordova plugin

i want add my custom plugin with java file and aar file
but error “Could not find :testaar2-debug”

the testaar2-debug.gradle is:

    dirs 'libs'
  dependencies {
   compile(name:'testaar2-debug', ext:'aar')
 android {
    packagingOptions {
      exclude 'META-INF/NOTICE'
      exclude 'META-INF/LICENSE'

the plugin.xml is:

<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-android-toast" version="1.0.0" xmlns="" xmlns:android="">
    <description>Android Toast Plugin</description>
    <license>Apache 2.0</license>
    <keywords>android, toast</keywords>

      <engine name="cordova" version=">=3.0.0" />

    <js-module name="AndroidToast" src="www/AndroidToast.js">
        <clobbers target="AndroidToast" />

    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="">
                <param name="android-package" value="" />
        <source-file src="src/android/" target-dir="src/com/android-toast" />
        <framework src="src/android/testaar2-debug.gradle" custom="true" type="gradleReference" />
        <resource-file src="src/android/testaar2-debug.aar" target="libs/testaar2-debug.aar" />


the is:

package com.nikolabreznjak;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;
import android.content.Context;
import android.widget.Toast;
import com.example.hpz420.testaar.TestAar;

public class AndroidToast extends CordovaPlugin {
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if ("show".equals(action)) {
            show(args.getString(0), callbackContext);
            return true;

        return false;

    private void show(String msg, CallbackContext callbackContext) {
          TestAar test = new TestAar();
         try {
             String str = test.showStr(msg);
             Toast.makeText(webView.getContext(), msg  , Toast.LENGTH_LONG).show();
         } catch (JSONException e) {

please help me

Use lib-file tag instead of resource-file tag for copying the .aar file, and remove the whole the gradle file as it’s not needed.

See an example on barcode plugin

1 Like

Thank you for your help:pray:
Problem solved by changing
dirs ‘src/main/libs’

Hey could you please provide a step by step procedure which one can follow to add an aar file as a plugin in an ionic project. I have checked a few sources but I am getting issues while implementing it. I am for sure missing out on something.
It would be great if you could just provide me with the steps…

Also, use implementation instead of compile in the plugin’s gradle file:

dependencies {
	implementation fileTree(include: ['*.aar'], dir: 'libs')

Hey, did anyone ever provide you the steps? I have the same situation.