I am creating the android side of my capacitor plugin for uwb.
for testing purposes its just a shell with methods to call…
plugin build is fine
in plugin project
npm run build
then in app project
npm install path
then npx cap sync
shows installed
✔ Copying web assets from dist to android/app/src/main/assets/public in 21.14ms
✔ Creating capacitor.config.json in android/app/src/main/assets in 956.71μs
✔ copy android in 37.29ms
✔ Updating Android plugins in 2.31ms
[info] Found 5 Capacitor plugins for android:
@capacitor/app@6.0.0
@capacitor/haptics@6.0.0
@capacitor/keyboard@6.0.0
@capacitor/status-bar@6.0.0
estimoteplugin@0.0.1
✔ update android in 55.04ms
[info] Sync finished in 0.094s
because it is a custom plugin, according to the doc i need to explicitly register it in MainActivity
package io.ionic.starter;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.sd.plugins.estimoteplugin.sduwbPlugin; // android studio found this
public class MainActivity extends BridgeActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.registerPlugin(sduwbPlugin.class);
}
}
and then sync in Android studio and run
but mainActivity crashes
NativePlugin com.sd.plugins.estimoteplugin.sduwbPlugin failed to load
com.getcapacitor.PluginLoadException: Unable to load plugin instance. Ensure plugin is publicly accessible
at com.getcapacitor.PluginHandle.load(PluginHandle.java:107)
at com.getcapacitor.PluginHandle.<init>(PluginHandle.java:65)
at com.getcapacitor.Bridge.registerPlugin(Bridg
the plugin top
package com.sd.plugins.estimoteplugin
import android.content.Context
import com.getcapacitor.JSObject
import com.getcapacitor.Plugin
import com.getcapacitor.PluginCall
import com.getcapacitor.PluginMethod
import com.getcapacitor.annotation.CapacitorPlugin
import kotlinx.coroutines.Job
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity
import java.util.Calendar;
import kotlinx.coroutines.flow.*
import kotlin.collections.hashMapOf
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.job
import kotlinx.coroutines.launch
@CapacitorPlugin(name = "sduwb")
public final class sduwbPlugin : Plugin() {
@PluginMethod
fun createManager(call: PluginCall) {
val timeKey:String =getMS();
Log.i("estimoteplugin", "createManager enter $timeKey");
// 3rd party lib calls here
Log.i("estimoteplugin", "createManager exit $timeKey");
val ret = JSObject()
ret.put("handle", timeKey)
call.resolve(ret)
}
}
maybe its the npm run build in the plugin…
Mac-mini:estimoteplugin sam$ npm run build android
> estimoteplugin@0.0.1 build
> npm run clean && tsc && rollup -c rollup.config.js android
> estimoteplugin@0.0.1 clean
> rimraf ./dist
android → dist/plugin.js, dist/plugin.cjs.js...
[!] Error: Could not resolve entry module (android).
Error: Could not resolve entry module (android).
at error (/Users/sam/ionic/estimoteplugin/node_modules/rollup/dist/shared/rollup.js:198:30)
at ModuleLoader.loadEntryModule (/Users/sam/ionic/estimoteplugin/node_modules/rollup/dist/shared/rollup.js:22306:20)
at async Promise.all (index 0)
Mac-mini:estimoteplugin sam$
if I do just npm run build
npm run build
> estimoteplugin@0.0.1 build
> npm run clean && tsc && rollup -c rollup.config.js
> estimoteplugin@0.0.1 clean
> rimraf ./dist
dist/esm/index.js → dist/plugin.js, dist/plugin.cjs.js...
created dist/plugin.js, dist/plugin.cjs.js in 19ms
Mac-mini:estimoteplugin sam$ ls dist
esm plugin.cjs.js plugin.cjs.js.map plugin.js plugin.js.map
Mac-mini:estimoteplugin sam$ ls dist/esm
definitions.d.ts definitions.js definitions.js.map index.d.ts index.js index.js.map
then dump the files
Mac-mini:estimoteplugin sam$ find dist
dist
dist/plugin.cjs.js
dist/esm
dist/esm/index.js
dist/esm/definitions.js
dist/esm/index.js.map
dist/esm/definitions.d.ts
dist/esm/index.d.ts
dist/esm/definitions.js.map
dist/plugin.cjs.js.map
dist/plugin.js.map
dist/plugin.js
I don’t think there is anything android in there