Add aar file to cordova plugin

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

the testaar2-debug.gradle is:

 repositories{
   jcenter()
   flatDir{
    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="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>AndroidToast</name
    <description>Android Toast Plugin</description>
    <license>Apache 2.0</license>
    <keywords>android, toast</keywords>

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

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

    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="AndroidToast.java">
                <param name="android-package" value="AndroidToast.java" />
            </feature>
        </config-file>
        <source-file src="src/android/AndroidToast.java" 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" />
    </platform>

</plugin>

the AndroidToast.java 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 {
    @Override
    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) {
             e.printStackTrace();
         }
    }
}

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 https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/plugin.xml#L46

1 Like

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