ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.47k stars 977 forks source link

bug: Cordova / Ionic Native plugin is not loaded. #2110

Closed OoDeLally closed 4 years ago

OoDeLally commented 4 years ago

Bug Report

Capacitor Version

npx cap doctor output:

▶ npx cap doctor
💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 1.3.0

  @capacitor/core: 1.3.0

  @capacitor/android: 1.3.0

  @capacitor/ios: 1.3.0

Installed Dependencies:

  @capacitor/ios not installed

  @capacitor/cli 1.3.0

  @capacitor/core 1.3.0

  @capacitor/android 1.3.0

[success] Android looking great! 👌

Affected Platform(s)

Current Behavior

I am trying to install @ionic-native/hotspot with cordova-plugin-hotspot. I've installed it (I believe) according to the documentation. Capacitor seems to recognize cordova-plugin-hotspot on npx cap copy

✔ Copying web assets from build to android/app/src/main/assets/public in 254.75ms
✔ Copying native bridge in 10.20ms
✔ Copying capacitor.config.json in 338.30μp
  Found 1 Cordova plugin for android
    cordova-plugin-hotspot (1.2.10)
✔ copy in 307.52ms

Once in the app, I fetch my plugin like this:

import { Capacitor, Plugins } from '@capacitor/core';
const foo => {
  console.log('Hotspot :', Capacitor.Plugins!.Hotspot); // undefined
  console.log('Plugins :', Object.keys(Plugins)); // App,Accessibility,Geolocation,Device,Keyboard,StatusBar,PushNotifications,BackgroundTask,Photos,Storage,LocalNotifications,Toast,Modals,Network,Permissions,SplashScreen,Camera,Clipboard,Haptics,Filesystem,WebView,Share,Browser,Motion
}

On android Logcat I can see what Capacitor loads (see the log below), but no trace of my plugin.

Expected Behavior

I expect to have the plugin available in my functions' runtime.

Sample Code or Sample Application Repo

https://github.com/OoDeLally/capacitor-plugin-bug

Reproduction Steps

Run the sample repo.

Other Technical Details

npm --version output: 6.4.1

node --version output: v12.13.0

Other Information

Logcat

2019-10-29 18:34:50.711 5167-5167/io.ionic.starter D/Capacitor: Starting BridgeActivity
2019-10-29 18:34:50.739 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: App
2019-10-29 18:34:50.748 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Accessibility
2019-10-29 18:34:50.752 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: BackgroundTask
2019-10-29 18:34:50.758 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Browser
2019-10-29 18:34:50.765 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Camera
2019-10-29 18:34:50.773 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Clipboard
2019-10-29 18:34:50.777 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Device
2019-10-29 18:34:50.780 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: LocalNotifications
2019-10-29 18:34:50.790 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Filesystem
2019-10-29 18:34:50.799 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Geolocation
2019-10-29 18:34:50.804 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Haptics
2019-10-29 18:34:50.809 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Keyboard
2019-10-29 18:34:50.814 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Modals
2019-10-29 18:34:50.819 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Network
2019-10-29 18:34:50.823 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Permissions
2019-10-29 18:34:50.825 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Photos
2019-10-29 18:34:50.829 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: PushNotifications
2019-10-29 18:34:50.838 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Share
2019-10-29 18:34:50.841 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: SplashScreen
2019-10-29 18:34:50.843 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: StatusBar
2019-10-29 18:34:50.847 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Storage
2019-10-29 18:34:50.853 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: Toast
2019-10-29 18:34:50.856 5167-5167/io.ionic.starter D/Capacitor: Registering plugin: WebView
2019-10-29 18:34:50.910 5167-5167/io.ionic.starter D/Capacitor: Loading app at http://localhost
jcesarmobile commented 4 years ago

That only prints Core plugins. And Cordova plugins are not added to Capacitor.Plugins object, that's only for Capacitor plugins.

You have to use Cordova plugins the same way you use them in Cordova apps.

Also, to copy the plugin files to the native project, run npx cap update android or npx cap sync android, copy only copies the web assets, but not the native classes.

OoDeLally commented 4 years ago

Thank you. Indeed the plugin was waiting for me in cordova.hotspot...

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.