question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom plugin is not being called for Android platform

See original GitHub issue

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 3.3.2
  @capacitor/core: 3.3.2
  @capacitor/android: 3.3.2
  @capacitor/electron: 3.3.2
  @capacitor/ios: 3.3.2

Installed Dependencies:

  @capacitor/cli 2.5.0
  @capacitor/ios 2.5.0
  @capacitor/core 2.5.0
  @capacitor/android 2.5.0
  @capacitor/electron not installed

[success] Android looking great! 👌
  Found 1 Capacitor plugin for ios:
    call-svc-plugin (0.0.1)
[success] iOS looking great! 👌

Platform(s)

Android

Current Behavior

I have created a CallSvcPlugin as described in creating-plugins that only has the echo functionality at this point. When I go to test the plugin, the iOS implementation is called when executed on an iOS device as expected. However the Android implementation is never called; instead the web implementation is being called. I am importing the plugin as follows…

import { Plugins } from '@capacitor/core';
const { CallSvcPlugin } = Plugins;

const reply1 = await CallSvcPlugin.echo({ value: 'You should not see this!' });
console.log(`[capacitor]: echo: ${reply1.value}`);

The plugin executed should just return “Hi from web!”, “Hi from iOS!”, or “Hi from Android!” depending on the platform used for test purposes.

Expected Behavior

Android custom plugin should be called. Device.getInfo() should return “android” when executed on Android device.

Code Reproduction

The code I’m testing is the same that was generated following creating-plugins

Other Technical Details

npm --version output: 6.14.15

node --version output: v14.17.6

pod --version output (iOS issues only): 1.9.2

Additional Context

  1. I noticed that Device.getInfo().platform always returns “web” instead of expected “android” result
  2. I noticed the npx cap doctor command results above show “Found 1 Capacitor plugin for ios” but not for Android. Although I see the following for npx cap sync
✔ Copying web assets from www to android/app/src/main/assets/public in 8.25ms
✔ Copying native bridge in 1.11ms
✔ Copying capacitor.config.json in 1.12ms
✔ copy in 22.77ms
✔ Updating Android plugins in 941.74μp
  Found 1 Capacitor plugin for android:
    call-svc-plugin (0.0.1)
✔ update android in 38.17ms
✔ Copying web assets from www to ios/App/public in 2.91ms
✔ Copying native bridge in 988.84μp
✔ Copying capacitor.config.json in 1.67ms
✔ copy in 9.65ms
✔ Updating iOS plugins in 2.31ms
  Found 1 Capacitor plugin for ios:
    call-svc-plugin (0.0.1)
✔ Updating iOS native dependencies with "pod install" (may take several minutes) in 4.44s
✔ update ios in 4.46s
✔ copy in 255.52μp
✔ update web in 4.48μp
Sync finished in 4.537s
  1. I am calling EnableHttpsSelfSigned.enable(this.bridge); in my MainActivity.java as shown here

  2. Output from Platform plugin… Platform.is.android: true Platform.is.capacitor: undefined Platform.is.chrome: true

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jcesarmobilecommented, Dec 6, 2021

Disabling SSL checks is a security vulnerability that leads to app rejections just for being there (even if not used in production), so code to do that won’t be part of Capacitor.

I’ve created a Capacitor plugin that disables ssl checks on both iOS and Android. Notice that it’s a personal plugin (@jcesarmobile/ssl-skip), not official from Ionic Team.

For tooling that provides dev servers with self signed certificates such as quasar, they should handle the SSL errors themselves, as they did for Capacitor 2, they can install/uninstall the plugin or use a similar code directly put into users projects.

1reaction
jcesarmobilecommented, Nov 19, 2021
  • I am calling EnableHttpsSelfSigned.enable(this.bridge); in my MainActivity.java as shown here

Hello. Why are you doing that? The problem is related to that, the bridge is not being injected and the platform is being detected as web, all android plugins will use the web version because of that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cordova Android Custom Plugin/App - Class Not Found ...
I've checked my platforms/android/ folder, and the plugin class is found at src/com/dev/plugin/PdfRenderPlugin.java as expected. What else ...
Read more >
Developing Custom Gradle Plugins
When the plugin is applied to a project, Gradle creates an instance of the plugin class and calls the instance's Plugin.apply() method. The...
Read more >
Android Plugin Development Guide - Apache Cordova
Android Plugin Development Guide. This section provides details for how to implement native plugin code on the Android platform.
Read more >
Chapter 8. Creating custom plugins - Apache Cordova in Action
In figure 8.2 the plugin has been updated to support both Android and iOS. ... the plugin is used no matter what platform...
Read more >
Known issues with Android Studio and Android Gradle Plugin
This error occurs on Linux-based platforms when starting the native debugger. It indicates that one of the libraries required by the native debugger...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found