Adding 3rd party plugins to capacitor app



  • I’m having an issue installing this “capacitor-navigationbar” plugin to my Capacitor app. I found my MainActivity.java file, however I do not know where I import the module as the plugin docs suggest I do. Any guidence will be extremely appreciated, thanks!

    both.png



  • Found out how its done:

    cd into src-capacitor folder: npm install capacitor-plugin-name

    then open file at src-capacitor/android/app/src/main/java/MainActivity.java

    there you will:
    import com.plugin-name
    and
    add(plugin-name)

    make sure neither your server nor your quasar client server is running otherwise you’ll get a bunch of ‘mkdir’ errors*

    then while remaining in src-capacitor you will run “npx cap sync android”

    go back to your quasar client and run “quasar dev -m capacitor -T android”

    make sure your server is still off and update your gradle on Android studio

    afterwards you will find the new plugin inside Plugins object in “@capacitor/core”

    you should be set to go. You’re welcome fellow newbie!



  • I’m following those steps, but having an error:
    error: cannot access CordovaPlugin add(BarcodeScanner.class);
    class file for org.apache.cordova.CordovaPlugin not found



  • Never mind, BarcodeScanner plugin works without adding it to MainActivity.java



  • When using Capacitor or Cordova plugins you should never not have to change .java files.



  • @dobbel in capacitor you do have to change it in some cases for registering plugins or when you are using local java files, it’s a nice feature of capacitor actually.


Log in to reply