question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct Android config for capacitor v3?

See original GitHub issue

The docs for this plugin mention that we should be adding this plugin to MainActivity.java. However, the capacitor v3 docs say that most plugins don’t need to be imported this way, instead they’re automatically imported.

https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading

Do we need this code block anymore?

import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {

          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(FirebaseAnalytics.class);
          }
        }
      );
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
KBRR11commented, Sep 8, 2021

If you use capacitor v3 you should change this.init(); to registerPlugin(FirebaseAnalytics.class);

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

    registerPlugin(FirebaseAnalytics.class);

  }
}
0reactions
brownoxfordcommented, Jan 25, 2022

Updated docs - because of the Capacitor 3’s automatic Android plugin loading, you no longer need to edit MainActivity.java when adding or removing files via NPM.

In Capacitor 3, it is preferred to automatically load the Android plugins. In MainActivity.java, the onCreate method can be removed. You no longer have to edit this file when adding or removing plugins installed via npm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Android | Capacitor Documentation
This article covers the basic modifications you'll need to make to your app. Read the Android Manifest docs to learn a whole lot...
Read more >
How to AUTOMATICALLY configure your Capacitor project ⚡️
We take an early look at the new Capacitor configuration tool called Capacitor configure which allows us to directly change native ...
Read more >
Ionic Capacitor Sync Command
Sync (copy + update) an Android or iOS device project with Ionic Capacitor Sync. Read our documentation to learn more about this command...
Read more >
Capacitor versions - Quasar Framework
Upgrading Capacitor · Delete the /src-capacitor/ios and /src-capacitor/android folders, but make sure that you are aware of any changes that you made in...
Read more >
Ionic + Capacitor 3 + Android shows distorted splash image ...
@capacitor/splash-screen: 0.3.6; @ionic/angular: 5.6.3. The following configuration is used: const config: CapacitorConfig = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found