android:TypeError: Cannot read property 'echo' of undefined
See original GitHub issueI am start developing a Native Capacitor Plugins for android platform unfortunately when i build & run my Plugin it’s work perfect in web implementation but in android i got a this Error .
https://github.com/rahadur/capacitor-admob
Logcat Error
E/Capacitor/Plugin/Console: ERROR TypeError: Cannot read property 'echo' of undefined
V/Capacitor: callback: -1, pluginId: Console, methodName: log, methodData: {"level":"error","message":"ERROR CONTEXT [object Object]"}
E/Capacitor/Plugin/Console: ERROR CONTEXT [object Object]
definations.ts
declare global {
interface PluginRegistry {
DemoPlugin?: PluginType;
}
}
export interface PluginType{
echo(options: { value: string }): Promise<{value: string}>;
other({options: any}): Promise<{response: boolean}>;
}
DemoPlugin.java
@NativePlugin()
public class DemoPlugin extends Plugin {
@PluginMethod()
public void echo(PluginCall call) {
String value = call.getString("value");
JSObject ret = new JSObject();
ret.put("value", value);
call.success(ret);
}
@PluginMethod()
public void other(PluginCall call) {
//String appId = call.getString("appId");
call.success(new JSObject().put("response", true));
}
}
MainActivity.java
public class MainActivity extends BridgeActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>(){{
add(DemoPlugin.class);
}});
}
}
As you can see i already implement Java side method and also Export to Capacitor in MainActivity
Ionic
Ionic:
ionic (Ionic CLI) : 4.6.0 (C:\Users\Rahadur\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.0.0-rc.1
@angular-devkit/build-angular : 0.11.4
@angular-devkit/schematics : 7.1.4
@angular/cli : 7.1.4
@ionic/angular-toolkit : 1.2.2
System:
NodeJS : v10.5.0 (C:\Program Files\nodejs\node.exe)
npm : 6.5.0
OS : Windows 10
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Cannot read property 'show' of undefined [react-native ...
i will try to make payment using Android-Pay. for android-pay require following object. global.PaymentRequest = require('react-native-payments ...
Read more >Cordova Build android. TypeError: Cannot read property ...
Hello I made Cordova build android pipeline in Azure DevOps But today I tried to rebuild the same code (This code was build...
Read more >Ionic android 12 splash error while adding cordova-android@11
here the error: Cannot read properties of null (reading 'find') TypeError: Cannot read properties of null (reading 'find') at E:\DEV\IONIC ...
Read more >expo build:android fails with `Cannot read property 'errors' of ...
After running expo build:android and uploading own keystore receive error Cannot read property 'errors' of undefined.
Read more >File Transfer Plugin - OutSystems
Trying to download a PDF using DownloadFile in File Transfer Plugin, but always get "Cannot read property 'activeScope' of undefined" (running on Android ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK it was total user error - in the plugin.ts, I’d called it “LocationControllerPlugin”, and in the Java code, the class was named “LoggerController”.
It might be nice if it stated in the documentation that the name must be identical between the Java and the definition in the plugin.ts - I had, perhaps, assumed wrongly that the bit of the name that mattered was the name of the plugin in the plugin registry, whereas in reality, it is the name of the interface in the typescript which needs to match.
Thanks both for your help!
Thanks for sharing your solution, because I had the same issue and without you it would’ve taken me more time to get it straight.