没有事件记录到Firebase

时间:2018-06-30 09:40:08

标签: android firebase google-play-services firebase-analytics

我正在尝试集成Firebase Analytics。但是,问题在于,每次尝试记录事件时,都不会报告任何事件(即使在通过adb启用调试模式进行Firebase分析之后也是如此)。这在模拟器和我的个人设备上都在发生。每当我记录事件时,我确实会在logcat中记录错误

  

工作线程上的任务异常:java.lang.NullPointerException:   尝试调用虚拟方法'java.lang.String   com.google.firebase.iid.FirebaseInstanceId.getId()'在空对象上   参考:   com.google.android.gms.internal.measurement.zzfc.zzgl(未知   来源:32)

我的gradle配置如下

顶级build.gradle

//顶层构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

buildscript {

    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-beta02'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'io.fabric.tools:gradle:1.+'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

项目的build.gradle

dependencies {
    implementation 'com.google.firebase:firebase-config:16.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    debugImplementation 'com.facebook.stetho:stetho:1.5.0'
    // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation "android.arch.lifecycle:common-java8:1.1.1"
    implementation "android.arch.persistence.room:runtime:1.1.1"
    implementation "com.google.android.gms:play-services-vision:15.0.2"
    implementation 'joda-time:joda-time:2.10'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') {
        transitive = true;
    }
    annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    // Paging
    implementation "android.arch.paging:runtime:1.0.0"
    // Test helpers for LiveData
    testImplementation "android.arch.core:core-testing:1.1.1"
    // Test helpers for Room
    testImplementation "android.arch.persistence.room:testing:1.1.1"
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

AndroidManifest

<receiver
    android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
    android:enabled="true"
    android:exported="false"/>
<receiver
    android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
    android:enabled="true"
    android:exported="true"
    android:permission="android.permission.INSTALL_PACKAGES">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

<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:enabled="true"
    android:exported="false"
    android:permission="android.permission.BIND_JOB_SERVICE" />

应用程序类

@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
    mFirebaseAnalytics.setUserId(Utils.fetchDeviceId(this));
    Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "Test");
    bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Test");
    bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Test");
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
}

1 个答案:

答案 0 :(得分:0)

终于找到了!这是一个明显的合并问题。由于失败,因此从未添加某些InstanceID服务。手动复制服务接收者并开始工作!