没有事件记录firebase怎么办?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (288)

我正在尝试集成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
}

Project的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);
}
提问于
用户回答回答于

终于找到了!这是一个明显的合并问题。InstanceID的一些服务没有被添加,因为它失败了。手动复制服务接收器并开始工作!

扫码关注云+社区

领取腾讯云代金券