shanebowyer
shanebowyer

Reputation: 21

My Ionic capacitor plugin I developed crashes my app on android

I developed a very simple ionic capacitor plugin. I used the stock standard echo method without changing a thing at it works in my app. I call the plugin and get an echo back. I then imported the cloudpossdk-1.5.2.aar which I need for my Point of Sale terminal. As soon as I implement this my app crashes on load. When I run the cloudpossdk-1.5.2.aar as a stand alone app and not as a plugin it works fine. I think it's a permissions issue. The app which works (not as a plugin) I gave it permission <uses-permission android:name="android.permission.CLOUDPOS_LED" /> I am stugling to work out how to debug this. Thanks in advance

package com.rts.plugins.hardwareapi;

import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;

import com.cloudpos.DeviceException;
import com.cloudpos.POSTerminal;
import com.cloudpos.led.LEDDevice;


@CapacitorPlugin(name = "hardwareapi")
public class hardwareapiPlugin extends Plugin {

    private hardwareapi implementation = new hardwareapi();

    @PluginMethod
    public void echo(PluginCall call) {

      LEDDevice lEDDevice =
        (LEDDevice) POSTerminal.getInstance(getContext()).getDevice("cloudpos.device.led");
      try {
        lEDDevice.open();
        lEDDevice.turnOff();
      } catch (DeviceException e) {
        e.printStackTrace();
      }


        String value = call.getString("value");
        JSObject ret = new JSObject();
        ret.put("value", implementation.echo(value));
        call.resolve(ret);
    }
}

So I have pulled in the cloudpossdk.aar file into my android ionic plugin but if I use implementation in the build.gradle I cannot compile and get this error

Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file

I found that I can change it to compileOnly then my project builds.

This is part of build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':capacitor-android')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    compileOnly files('src/libs/cloudpossdk-1.5.2.aar')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
}

I found this error below which I am wondering if not including the cloudpos lib when building apk

java.lang.ClassNotFoundException: Didn't find class "com.cloudpos.POSTerminal" on path: DexPathList[[zip file "/data/app/io.ionic.starter-1/base.apk"],nativeLibraryDirectories=[/data/app/io.ionic.starter-1/lib/arm, /vendor/lib, /system/lib]]

Upvotes: 0

Views: 1275

Answers (1)

shanebowyer
shanebowyer

Reputation: 21

I got it working but believe its a hack. I brought the .aar into my capacitor plugin but I also brought it into my app which is consuming the plugin. Surely a plugin is just that, include it and use it.

Anyway, it solves the problem for me.

Upvotes: 1

Related Questions