React-native-onesignal: Crash on android when call init()

Created on 9 May 2018  路  15Comments  路  Source: OneSignal/react-native-onesignal

When I call function OneSignal.init(), my app crashes immediately

My code

componentDidMount() {
    OneSignal.init('7b5d2490-xxxxxxxxxxxxxxxxxxxxx');
    ...
}

"react": "16.3.1",
"react-native": "0.55.4",
"react-native-onesignal": "^3.2.0",

Android log:

05-09 10:03:30.068: D/FirebaseApp(4036): com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
05-09 10:03:30.072: E/AndroidRuntime(4036): FATAL EXCEPTION: pool-7-thread-1
05-09 10:03:30.072: E/AndroidRuntime(4036): Process: com.appartment_app, PID: 4036
05-09 10:03:30.072: E/AndroidRuntime(4036): java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.appartment_app. Make sure to call FirebaseApp.initializeApp(Context) first.
05-09 10:03:30.072: E/AndroidRuntime(4036): at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
05-09 10:03:30.072: E/AndroidRuntime(4036): at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
05-09 10:03:30.072: E/AndroidRuntime(4036): at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source)
05-09 10:03:30.072: E/AndroidRuntime(4036): at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent(Unknown Source)
05-09 10:03:30.072: E/AndroidRuntime(4036): at com.google.firebase.iid.zzc.run(Unknown Source)
05-09 10:03:30.072: E/AndroidRuntime(4036): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
05-09 10:03:30.072: E/AndroidRuntime(4036): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
05-09 10:03:30.072: E/AndroidRuntime(4036): at java.lang.Thread.run(Thread.java:818)
05-09 10:03:30.136: D/ReactNative(4036): ReactInstanceManager.detachViewFromInstance()
05-09 10:03:30.419: D/EGL_emulation(4036): eglMakeCurrent: 0xedb13fc0: ver 2 0 (tinfo 0xea1bcc40)
05-09 10:03:30.420: E/Surface(4036): getSlotFromBufferLocked: unknown buffer: 0xf407eec0
05-09 10:03:33.523: I/Process(4036): Sending signal. PID: 4036 SIG: 9

Most helpful comment

If your app is getting the push notification and crashing immediately, you have to add the following line in your app\bulild.gradle

compile 'com.google.firebase:firebase-messaging:17.1.0'

you may also want to add the following line in your componentDidMount() :

OneSignal.registerForPushNotifications();

All 15 comments

Hi @building-software-2018 , are you only using react-native-onesignal as a dependency, or does your application have other dependencies as well? Are you using Firebase analytics?

@Nightsd01 related to #489, i've added OneSignal.init() to my code and app crashes with same error.

Before adding OneSignal.init() from android logcat, i've seen "OneSignal.init not called".

I'm using

compileSdkVersion 23
buildToolsVersion "23.0.1"
minSdkVersion 16
targetSdkVersion 22

compile "com.android.support:appcompat-v7:23.0.1"

classpath 'com.android.tools.build:gradle:2.2.3'

I tried to update to latest versions or, at least, get those used on example project and my app doesn't build anymore with this error

Task :react-native-google-analytics-bridge:compileDebugJavaWithJavac E:\Progetti\TruckyV2\node_modules\react-native-google-analytics-bridge\android\src\main\java\com\idehub\GoogleAnalyticsBridge\GoogleAnalyticsBridgePackage.java:8: error: package com.google.android.gms.tagmanager does not exist import com.google.android.gms.tagmanager.ContainerHolder;

Hope this helps

@shardick that would be an issue with the google analytics bridge package you are using. Try defining your google play services version in android/gradle.properties like this:

googlePlayServicesVersion=11.8.0

@Nightsd01 fixed now, using this comment

https://github.com/idehub/react-native-google-analytics-bridge/issues/238#issuecomment-381555995

for @building-software-2018 , this is my root build.gradle

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

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

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

allprojects {
    repositories {
         configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion '12.0.1'
                }
            }
        }
        mavenLocal()
        jcenter()
        google()
        maven {
            url "https://jitpack.io"
        }
        maven {
            url 'https://maven.google.com'
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26
                buildToolsVersion '26.0.2'
            }
        }
    }
}

in app build.gradle

compileSdkVersion 27
buildToolsVersion "27.0.3"
compile "com.android.support:appcompat-v7:27.1.0"

compile, run, load and subscribe on OneSignal after OneSignal.init

@building-software-2018 if you鈥檙e still having this issue could you post your full app/build.gradle?

Sent with GitHawk

@building-software-2018 Due to a lack of response I'll assume you were able to fix the issue. If you're still having this problem please feel free to respond and I'll reopen

same issue
but i found why issue occurs but no idea how to solve
when i removed react native admob it works
any one can solve this issue???

Hi all,

I've faced the same issue, app crashes on opening when OneSignal.init() is called.
Apart onesignal I also use react-native-maps (found a ticket that can be conflict when using both libs, but in my case all is configured properly) and react-native-deviceinfo.
What possible reasons can be?

Hello @aramknyazyan I have same issues and I know it's a clash with react-native-maps. Have you been able to resolve this?

Hi @kenshinman, I didn't waste my time on it, just switched to react-native-push-notification :)

Same issue.

Working correctly on iOS and if i remove the init() and other One Signal calls then everything else works.

my root build.gradle:

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

}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

my /app build.gradle:

buildscript {
   repositories {
       maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal 
   }
   dependencies {
       classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.0, 0.99.99]'
   }
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.nativebasekitchensink"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile project(':react-native-onesignal')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

I have the same issue, I'm only using this packages:
"native-base": "^2.4.3",
"react-native-image-slider": "^2.0.3",
"react-native-onesignal": "^3.2.5",
"react-native-photo-view": "^1.5.2",
"react-native-router-flux": "^4.0.0-beta.28"
Tried everything the problem still accures. App work fine If I remove:

componentWillMount() {
    OneSignal.init("00000000000");
    OneSignal.addEventListener('received', this.onReceived);
    OneSignal.addEventListener('opened', this.onOpened);
    OneSignal.addEventListener('ids', this.onIds);
}

bump. anyone else experiencing this or have a fix for it?

If your app is getting the push notification and crashing immediately, you have to add the following line in your app\bulild.gradle

compile 'com.google.firebase:firebase-messaging:17.1.0'

you may also want to add the following line in your componentDidMount() :

OneSignal.registerForPushNotifications();

Thanks @mjm918 adding the compile worked.
I had the same issue. Strangely it started to happen without any changes from my side. Even on the device.

Was this page helpful?
0 / 5 - 0 ratings