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.

legomolina
  • 1,043
  • 2
  • 13
  • 33

7 Answers7

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);
  }
}
Erkhemee
  • 131
  • 1
  • 2
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

Denis Grushak
  • 185
  • 1
  • 7
2

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

  • 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" ? – Andrea Nicola Jun 07 '21 at 12:00
  • 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. https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading – legomolina Jun 12 '21 at 22:42
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.

legomolina
  • 1,043
  • 2
  • 13
  • 33
  • Hello, for my part, this does not seem to work. Do you have more details on the procedure to follow? Thank you. – SiteXw Apr 26 '21 at 16:02
  • 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.. – legomolina Jun 15 '21 at 15:43
  • I don't understand why critical portions of the capacitor package are treated like optional dependencies. – Alex Jun 30 '21 at 02:23
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.

Sundbox
  • 81
  • 3
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

sweak
  • 1,369
  • 2
  • 6
  • 21
akr
  • 1
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

Mr Benn
  • 466
  • 1
  • 6
  • 19