hansemannn / titanium-firebase-analytics

Use the Firebase Analytics SDK in Axway Titanium 🚀
Other
35 stars 18 forks source link

Won't work with CloudMessaging module #41

Closed DouglasHennrich closed 5 years ago

DouglasHennrich commented 5 years ago

I'm trying to add this module and CloudMessaging but when I do so, my app stops to work and freezes on splash screen without any error on logs:

// TRACE LOG
-- Start application log -----------------------------------------------------
[WARN]  zygote: Unexpected CPU variant for X86 using defaults: x86
[INFO]  TiApplication: (main) [0,0] checkpoint, app created.
[INFO]  MultiDex: VM with version 2.1.0 has multidex support
[INFO]  MultiDex: Installing application
[INFO]  MultiDex: VM has multidex support, MultiDex support library is disabled.
[DEBUG] FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
[DEBUG] FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
[INFO]  FA: App measurement is starting up, version: 11020
[INFO]  FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
[INFO]  FA: To enable faster debug mode event logging run:
[INFO]  FA:   adb shell setprop debug.firebase.analytics.app br.com.kyddo.enterprise
[INFO]  FirebaseInitProvider: FirebaseApp initialization successful
[DEBUG] APSAnalytics: APSAnalytics initialization started...
[DEBUG] AndroidRuntime: Shutting down VM
[TRACE] updating tiapp metadata with Appcelerator Platform...
[TRACE] Uploaded tiapp metadata with Appcelerator Platform!

If I remove Analytics, my app works just fine...

this is my analytics section on android:

<!-- Firebase Analytics -->
        <service
          android:name="com.google.android.gms.measurement.AppMeasurementService"
          android:enabled="true"
          android:exported="false" />

        <service
          android:name="com.google.android.gms.measurement.AppMeasurementJobService"
          android:permission="android.permission.BIND_JOB_SERVICE"
          android:enabled="true"
          android:exported="false" />

        <service
          android:name="br.com.kyddo.enterprise.gcm.RegistrationIntentService"
          android:exported="false" />

        <receiver
          android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
          android:enabled="true" >

          <intent-filter>
            <action
              android:name="com.google.android.gms.measurement.UPLOAD" />
          </intent-filter>
        </receiver>

        <!-- Only add the GCM-related tags if you are using push notifications as well -->
        <service
          android:name="br.com.kyddo.enterprise.gcm.GcmIntentService"
          android:exported="false" >

          <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          </intent-filter>
        </service>

        <service
          android:name="br.com.kyddo.enterprise.gcm.GcmIntentService"
          android:exported="false" >

          <intent-filter>
            <action android:name="com.google.android.c2dm.intent.SEND" />
          </intent-filter>
        </service>

        <service
          android:name="br.com.kyddo.enterprise.gcm.GcmIDListenerService"
          android:exported="false" >

          <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
          </intent-filter>
        </service>
        <!--  -->

this is my CloudMessaging just below Analytics:

<!-- Firebase CloudMessaging -->
        <meta-data
          android:name="com.google.firebase.messaging.default_notification_icon"
          android:resource="@drawable/notificationicon"/>

        <service android:name="br.com.kyddo.enterprise.gcm.RegistrationIntentService" android:exported="false" />

        <receiver
          android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
          android:enabled="true">

          <intent-filter>
            <action android:name="com.google.android.gms.measurement.UPLOAD" />
          </intent-filter>
        </receiver>

        <service
          android:name="br.com.kyddo.enterprise.gcm.GcmIDListenerService"
          android:exported="false">

          <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
          </intent-filter>
        </service>

        <!-- Commented as it's already added by Analytics -->
        <!-- <service
          android:name="br.com.kyddo.enterprise.gcm.GcmIntentService"
          android:exported="false">

          <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          </intent-filter>
        </service>

        <service
          android:name="br.com.kyddo.enterprise.gcm.GcmIntentService"
          android:exported="false">

          <intent-filter>
            <action android:name="com.google.android.c2dm.intent.SEND" />
          </intent-filter>
        </service> -->
        <!--  -->

my firebase lib:

/* ===============================
@ Imports
=============================== */
const FirebaseAnalytics = require('firebase.analytics')

/* ===============================
@ Consts & Lets
=============================== */
let Initialized

/* ===============================
@ Functions
=============================== */
Alloy.Firebase = {
    Config: callback => {
        const core = require('firebase.core') // eslint-disable-line
        const configured = core.configure()
        Alloy.Log(`[Firebase - config]: ${JSON.stringify(configured)}`)
        Initialized = true
        callback && callback()
    },
    CloudMessaging: require('firebase.cloudmessaging'), // eslint-disable-line
    Analytics: (event, params) => {
        if (!Alloy.CFG.FIREBASE || !Initialized) return

        params = params || (OS_IOS ? { action: 'click', category: 'click' } : null)

        Alloy.Log(
            `[Firebase - Analytics]: ${JSON.stringify({
                event,
                params,
            })}`,
        )
        OS_ANDROID && FirebaseAnalytics.log(event, params)
        OS_IOS && FirebaseAnalytics.log(event)
    },
}

Also, I already have my google-services.json under /app/assets/android/

I'm using: 7.5.1.GA playservices: 11.0.40 core: 3.0.2 Analytics: 2.2.2 CloudMessaging: 1.4.1

hansemannn commented 5 years ago

We use both in production without issues. Not sure why, not it works. Currently not much time to debug this, so please try to initialize it on the container open event which ensures that it always has a proper activity to use.

DouglasHennrich commented 5 years ago

Maybe it's something wrong with my tiapp.xml ? can you post yours? I need to follow sequence when I'm adding those tags on android's section?

Thanks @hansemannn

hansemannn commented 5 years ago

Fixed by using latest versions and play-services 16.x.