Code Monkey home page Code Monkey logo

Comments (7)

vimalkumar015 avatar vimalkumar015 commented on September 14, 2024

Please post the full code of MainActivity,java

from firebase-analytics.

losciur avatar losciur commented on September 14, 2024

That is the full code...
In the previous image I just cut the first line where there is my package name...

The app is created with ionic angular capacitor 3.
Everything works fine except firebase.

I repost here MainActivity.java:


package it.piemonte.arpa.meteo3RTest;


  import com.getcapacitor.BridgeActivity;
  
  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);
        }
      }
    );
  }
}

Here my npx cap sync android


✔ Copying web assets from www to android/app/src/main/assets/public in 1.77s
✔ Creating capacitor.config.json in android/app/src/main/assets in 1.60ms
⠴ copy android [info] Found 4 Cordova plugins for android:
       [email protected]
       [email protected]
       [email protected]
       [email protected]
✔ copy android in 1.86s
✔ Updating Android plugins in 31.61ms
[info] Found 11 Capacitor plugins for android:
       @capacitor-community/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
       @capacitor/[email protected]
⠙ update android [info] Found 4 Cordova plugins for android:
       [email protected]
       [email protected]
       [email protected]
       [email protected]
✔ update android in 117.29ms
[info] Sync finished in 1.978s

Here my ionic info


Ionic:

   Ionic CLI                     : 6.16.1 (/home/losciur/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.8
   @angular-devkit/build-angular : 12.0.3
   @angular-devkit/schematics    : 12.0.3
   @angular/cli                  : 12.0.3
   @ionic/angular-toolkit        : 4.0.0

Capacitor:

   Capacitor CLI      : 3.0.0
   @capacitor/android : 3.0.0
   @capacitor/core    : 3.0.0
   @capacitor/ios     : not installed

Utility:

   cordova-res : 0.15.3
   native-run  : 1.3.0

System:

   NodeJS : v14.17.0 (/home/losciur/.nvm/versions/node/v14.17.0/bin/node)
   npm    : 6.14.13
   OS     : Linux 5.4

from firebase-analytics.

vimalkumar015 avatar vimalkumar015 commented on September 14, 2024

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
import java.util.ArrayList;

Add these imports in MainActivity.java

from firebase-analytics.

brownoxford avatar brownoxford commented on September 14, 2024

This is a duplicate of #94, closing.

from firebase-analytics.

losciur avatar losciur commented on September 14, 2024

Thanks for the help!
Mixing what you suggest and what in capacitor documentation and in #94 I think that the better solution is:


  import android.os.Bundle;
  import com.getcapacitor.BridgeActivity;
  import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;


public class MainActivity extends BridgeActivity {

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

        registerPlugin(FirebaseAnalytics.class);
     }

}

Maybe you may add this lines in the documentation of this plugin, because the lines you suggest are deprecated.

from firebase-analytics.

brownoxford avatar brownoxford commented on September 14, 2024

The capacitor documentation indicates that the registerPlugin call is not needed for plugins installed via NPM, which is the case for the firebase-analytics plugin. You only need to call registerPlugin if you have local custom plugins that you developed for your app and are not installing from NPM.

from firebase-analytics.

losciur avatar losciur commented on September 14, 2024

You're right about the capacitor documentation,
but if I leave the code you suggest:

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import com.getcapacitor.community.firebaseanalytics.FirebaseAnalytics;
import java.util.ArrayList;

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);
        }
      }
    );
  }
}

I got this (Android Studio 4.2.1):

immagine

On the other side, when I install any official capacitor plugins via npm I don't have to modify the ManiActivity.java file in Android Studio (I don't know why).

Thank you very much for your work and this explanation words, I'm very happy to try to understand something more in plugin.

from firebase-analytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.