Capacitor v3 plugins not working on android build
Asked Answered
A

7

13

I'm using capacitor v3 beta and there are no problem working in web and iOS but can't run android app. Build is done fine but when running the app appears this error:

E/Capacitor/Console: File: http://localhost/vendor-es2015.js - Line 41296 - Msg: ERROR Error: Uncaught (in promise): Error: "Storage" plugin is not implemented on android
    Error: "Storage" plugin is not implemented on android

To solve this error I've removed the storage plugin and replaced with ionic/storage plugin. But when I use other plugin, for example the Keyboard, the error shows up saying that Keyboard plugin is not implemented on android.

So I suppose that there is some problem with Android builds or project configuration.

These are de node dependencies in my package.json

"@capacitor/android": "^3.0.0-beta.6",
"@capacitor/core": "^3.0.0-beta.1",
"@capacitor/storage": "^0.3.1",

And my capacitor.config.json file

{
    "appId": "net.flowww.me",
    "appName": "FLOWwwMe",
    "bundledWebRuntime": false,
    "npmClient": "npm",
    "webDir": "www",
    "cordova": {}
}

iOS version works well with this configuration.

Acyl answered 4/3, 2021 at 15:11 Comment(1)
Maybe try using the latest. npm install @capacitor/storage@latestAzeotrope
A
1

After creating new project and reviewing file differences saw that I have not installed

"@capacitor/cli": "^3.0.0-beta.6"

So I installed it and all compiles successfully.

Acyl answered 5/3, 2021 at 12:7 Comment(3)
Hello, for my part, this does not seem to work. Do you have more details on the procedure to follow? Thank you.Aixlachapelle
Nop, maybe the error is not the same. Did you try uninstalling all capacitor-related packages installing them following the install guide on capacitor site? Maybe some old lib stil remains on your node_modules folder..Acyl
I don't understand why critical portions of the capacitor package are treated like optional dependencies.Gynophore
V
7

Storage plugin not worked after Ionic v3 upgrades from v2. It work after manually adding a plugin to MainActivity.java for me:

package com.ionic.app;

import android.os.Bundle;

import com.getcapacitor.BridgeActivity;
import com.capacitorjs.plugins.storage.StoragePlugin;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    registerPlugin(StoragePlugin.class);
  }
}
Vituperation answered 8/7, 2021 at 9:52 Comment(0)
R
3

I also faced the same problem when upgrading from capacitor 2 to 3

As it turned out, I forgot to execute:

npx cap sync android

This solved the problem

Rhapsodize answered 29/5, 2021 at 13:20 Comment(0)
W
2

you must in mainActivity : add(StoragePlugin.class);

Whoop answered 1/6, 2021 at 2:33 Comment(2)
This worked for me, but why it doesn't work following the minimal instructions of the official storage plugin guide? Does MainActivity generate automatically every time i do "ionic build" or "npx cap sync" ?Dagostino
As far as I know, with Capacitor v3 there is no need to push items to List in main activity because Capacitor imports them dinamically. capacitorjs.com/docs/updating/…Acyl
A
1

After creating new project and reviewing file differences saw that I have not installed

"@capacitor/cli": "^3.0.0-beta.6"

So I installed it and all compiles successfully.

Acyl answered 5/3, 2021 at 12:7 Comment(3)
Hello, for my part, this does not seem to work. Do you have more details on the procedure to follow? Thank you.Aixlachapelle
Nop, maybe the error is not the same. Did you try uninstalling all capacitor-related packages installing them following the install guide on capacitor site? Maybe some old lib stil remains on your node_modules folder..Acyl
I don't understand why critical portions of the capacitor package are treated like optional dependencies.Gynophore
P
0

In Capacitor's v2 doc, in the page dedicated to Storage Plugin (https://capacitorjs.com/docs/apis/storage) the import is done like:

import { Storage } from '@capacitor/storage';

Then in the Capacitor's v2 doc for Using Plugins (https://capacitorjs.com/docs/v2/apis) you'll find that:

  1. Import the Plugins object. It represents the registry of all Capacitor plugins.
import { Plugins } from '@capacitor/core';
  1. Get a plugin from the Plugin Registry (Plugins object).
const { Browser } = Plugins;
  1. Use the plugin API:
async openBrowser() {
  // On iOS, for example, open the URL in SFSafariViewController (the in-app browser)
  await Browser.open({ url: "https://ionicframework.com" });
}

A common mistake is to import a plugin directly, then use the plugin API >immediately, resulting in the web implementation being used:

import { Browser } from '@capacitor/core';

async openBrowser() {
  // On iOS, for example, this will open the URL in Safari instead of
  // the SFSafariViewController (in-app browser)
  await Browser.open({ url: "https://ionicframework.com" });
}

By using the plugins from the plugin registry (Plugins object), the native implementation of the plugin is used (if available), with fallback to the web version.

So if you're using Quasar with Capacitor v2 you probably gone crazy like me. Just replace Browser with Storage.

Maybe in v3 that problem is solved and that's why legomolina's answer works.

Psychosis answered 14/6, 2021 at 14:21 Comment(0)
T
0

For Capacitor V3 plugins (tested on Android 11 & Ionic 5)

  1. capacitor.plugins.json has the entry for Storage plugin,
  2. MainActivity.java should not have the onCreate function, where CapV3 uses native API,
  3. Try setting minifyEnabled=false in build.gradle.

If error disappears, create pro-guard rules in proguard-rules.pro as in https://github.com/ionic-team/capacitor/issues/739

Theis answered 30/11, 2021 at 10:32 Comment(0)
R
0

I found the issue was solved by simply starting up Android Studio. It sync'd Gradle automatically and then I just restarted my Android dev environment - the error was gone and I was able to access Storage as per the capaitor plugin docs.

See https://capacitorjs.com/docs/android/troubleshooting#plugin-not-implemented

Refugee answered 1/4, 2022 at 17:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.