0

I am trying to use Firebase crash reporting and notifications on an Android Project I inherited from my predecessor in my place of work.

For some unknown reason Firebase or OneSignal has refused to work on the project,it doesn't matter whether the app is in background or not. I implemented Firebase using the Android Studio Assistant.

However if I create fresh projects and implement Firebase or OneSignal it works glitchlessly.

Module build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'


    defaultConfig {
        applicationId "com.myfirm.appname"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.facebook.android:facebook-android-sdk:4.20.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support:customtabs:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:cardview-v7:25.3.0'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    compile 'com.onesignal:OneSignal:3.4.3'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    testCompile 'junit:junit:4.12'
}


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

Project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.myfirm.appname">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@drawable/notification_icon"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:node="replace">

        <service
            android:name=".services.TokenService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <meta-data android:name="onesignal_app_id" android:value="@string/onesignal_app_id" tools:replace="android:value"/>
        <meta-data android:name="onesignal_google_project_number" android:value="@string/onesignal_google_project_number" tools:replace="android:value"/>

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_appid" />


        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="fbXXXXXXXXXXXX" />
            </intent-filter>
        </activity>

        // More Activities
    </application>

</manifest>

MyApplication

@Override
    public void onCreate() {
        super.onCreate();
        OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.NONE);
        FirebaseApp.initializeApp(this);
        // Removed some code
        OneSignal.startInit(this)
                .setNotificationReceivedHandler(new OneSignalMessageReceiver())
                .init();
    }

A few things to note:

  1. The app is always in background (I launched it and pressed the home button) when I send the notifications.

  2. On the dashboards (both Firebase and OneSignal), the message says it's been successfully sent.

  3. I'm getting the device token on Firebase and I uses it to send notifications. Sometimes it says notification has been sent and at other times it says token not registered.

  4. The reason why it appears I'm using both Firebase and OneSignal is because I tried Firebase first, it didn't work. Then I used OneSignal hoping hat it would Work but it didn't. So if any one works, I remove the other.

  5. The google-services.json exists in ProjectName > app and yes, the package name correspond with that in manifest.

  6. The crash reports are not showing on Firebase dashboard even when the app has crashed severally.

AL.
  • 36,815
  • 10
  • 142
  • 281
X09
  • 3,827
  • 10
  • 47
  • 92

0 Answers0