how can I generate an AAR that has the functions of firebase analytics and then use it in other android studio projects?

0

I have created an app in android studio which has the connection to firebase analytics, that is, it already registers events and everything works fine. Then I generate an AAR from that app. I create a second app in which I import this AAR library to reuse everything that is there including the event log of the firebase. When I use the method that registers the event I get the following error

07-04 16:15:48.254 2486-2486/com.example.pcr.ejemplo_uso_lib_gtm E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pcr.ejemplo_uso_lib_gtm, PID: 2486
    java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.analytics.FirebaseAnalytics.logEvent(java.lang.String, android.os.Bundle)' on a null object reference
        at com.example.pcr.app_gtm_prueba.MainActivity.registrarEvento(MainActivity.java:85)
        at com.example.pcr.ejemplo_uso_lib_gtm.EjemploActivity$2.onClick(EjemploActivity.java:33)
        at android.view.View.performClick(View.java:6294)
        at android.view.View$PerformClick.run(View.java:24770)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

what I have in the first app from which I generate the

public class EjemploActivity extends AppCompatActivity {
    Button btn_com_var, btn_prue_gtm;
    MainActivity main_gtm = new MainActivity();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ejemplo);
        main_gtm.MainActivity("pruebaLIB","pruba_name_lib","prueba_lib_tipo");
        btn_com_var = (Button) findViewById(R.id.btn_com_var);
        btn_prue_gtm = (Button) findViewById(R.id.btn_prue_gtm);

        btn_com_var.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                main_gtm.comprobarVariables(bundle);
            }
        });
    btn_prue_gtm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Bundle bundle = new Bundle();
            main_gtm.registrarEvento(bundle);
        }
    });

    }
}

and this is what I have in the app that consumes the AAR

public class EjemploActivity extends AppCompatActivity {
    Button btn_com_var, btn_prue_gtm;
    MainActivity main_gtm = new MainActivity();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ejemplo);
        main_gtm.MainActivity("pruebaLIB","pruba_name_lib","prueba_lib_tipo");
        btn_com_var = (Button) findViewById(R.id.btn_com_var);
        btn_prue_gtm = (Button) findViewById(R.id.btn_prue_gtm);
        btn_com_var.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                main_gtm.comprobarVariables(bundle);
            }
        });
    btn_prue_gtm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Bundle bundle = new Bundle();
            main_gtm.registrarEvento(bundle);
        }
    });

    }
}

I would be very grateful if you could help me, it is the first time I have asked a question here if there is something missing, they tell me. Thanks in advance.

    
asked by Gustavo Marin Multiplica 04.07.2018 в 19:53
source

0 answers