I am trying to register capacitor v3 plugins to Android but nothing works

Viewed 1297

I am using Ionic 5, Capacitor 3, Android 4.2.2 Node 14...etc

I am trying to install capacitor plugins geolocation and storage in Android like so:

package io.ionic.seakah;

import android.os.Bundle;
import com.capacitorjs.plugins.storage.StoragePlugin;>>>ERROR...cannot resolve symbol
import com.capacitorjs.plugins.geolocation.Geolocation;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    registerPlugin(StoragePlugin.class); >>>ERROR...cannot resolve symbol
    registerPlugin(Geolocation.class);>>>ERROR...registerPlugin not recognized

    // Initializes the Bridge
    // this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
       //Additional plugins you've installed go here
       //Ex: add(TotallyAwesomePlugin.class);

   // }});
  }

first thing of note is that the init method is deprecated and the add() is replaced with registerPlugin()...the problem is after all the adjustments the plugins aren't recognized... I have made sure to run npm cap sync and also rebuild from inside Android studio. The existing documentation mostly speaks to Capacitor V2. would appreciate any help here...Thanks

1 Answers

You do not need to register Geolocation or Storage plugins manually. Follow the documentation. For Geolocation you should update Manifest for Android and it will work fine.

Plugins registration needed for custom plugins (probably for community plugins too): https://capacitorjs.com/docs/plugins/android

Related