“FCM” App Crashes on this line getToken() “java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process” [duplicate]Default FirebaseApp is not initializedjava.lang.IllegalStateException: FirebaseApp with name [DEFAULT]enable Firebase Crash Reporting in AndroidDefault FirebaseApp is not initializedHow to display Map on emulatorKotlin fails to compile a libraryFirebase API initialisation failure - Not updating the list view from firebaseAndroid Studio 3.2.1 - New project fails to runNo static field navigationView of type I in class Lcom/mapbox/services/android/navigation/ui/v5/R$idjava.lang.IllegalStateException: Default FirebaseApp is not initialized in this processandroid gradle error: libraries must use the exact same version specification.found version 28.0.0

Why should I pay for an SSL certificate?

Weird resistor with dots around it on the schematic

Visa on arrival to exit airport in Russia

Expressing a chain of boolean ORs using ILP

How do I answer an interview question about how to handle a hard deadline I won't be able to meet?

Airline power sockets shut down when I plug my computer in. How can I avoid that?

How to gracefully leave a company you helped start?

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

Output the list of musical notes

Is nullptr falsy?

Knights and Knaves on a (Not So) Deserted Island

Quick destruction of a helium filled airship?

Why do we use low resistance cables to minimize power losses?

Why do so many people play out of turn on the last lead?

Does writing regular diary entries count as writing practice?

Why does "auf der Strecke bleiben" mean "to fall by the wayside"?

The space of cusp forms for GL_2 over F_q(T)

How can I enter recovery mode (for Mac OS, on an iMac) remotely?

Eric Andre had a dream

How do I ask for 2-3 days per week remote work in a job interview?

Have there ever been other TV shows or Films that told a similiar story to the new 90210 show?

Does Medium Armor's Max dex also put a cap on the negative side?

What are these panels underneath the wing root of a A380?

Did Michelle Obama have a staff of 23; and Melania have a staff of 4?



“FCM” App Crashes on this line getToken() “java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process” [duplicate]


Default FirebaseApp is not initializedjava.lang.IllegalStateException: FirebaseApp with name [DEFAULT]enable Firebase Crash Reporting in AndroidDefault FirebaseApp is not initializedHow to display Map on emulatorKotlin fails to compile a libraryFirebase API initialisation failure - Not updating the list view from firebaseAndroid Studio 3.2.1 - New project fails to runNo static field navigationView of type I in class Lcom/mapbox/services/android/navigation/ui/v5/R$idjava.lang.IllegalStateException: Default FirebaseApp is not initialized in this processandroid gradle error: libraries must use the exact same version specification.found version 28.0.0






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1
















This question already has an answer here:



  • Default FirebaseApp is not initialized

    26 answers



FCM (Firebase Cloud Messaging) initialize issue



I started working on FCM module, I fallowed as per the firebase guidelines. i'm getting two exceptions like RuntimeException and IllegalStateException. Firebase init default but why and what is the issue in FCM.



1. From Android Studio tools -> Firebase -> Cloud Messaging.



2. I fallowed Set up Firebase Cloud Mesasging.



I fallowed below link:



https://firebase.google.com/docs/cloud-messaging/android/client



App : Build.gradle



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:17.4.0'
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'



Project : Build.gradle



buildscript 
repositories
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.1.0'

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



allprojects
repositories
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir



In MainActivity.class, i trying to get token but app crashes.



 public class MainActivity extends AppCompatActivity 

public static final String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String tokenId = FirebaseInstanceId.getInstance().getToken(); //Crashes in this line
Log.d("SH", tokenId);




in logcat i got two exceptions



 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package PID: 29368
java.lang.RuntimeException: Unable to start activity ComponentInfocom.package.testfcm/com.package.MainActivity: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2861)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:1)
at com.package.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7032)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1236)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6626) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) 


Finally i found solutions, Now i able to get FCM Token.



In project build.gradle file you need add single line code code i.e., mavenLocal().



Fallow as per the below solutions cross check the project : build.gradle file and app : build.gradle file.



Project : build.gradle



buildscript 
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'

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



allprojects
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir




App : build.gradle



apply plugin: 'com.android.application'


android
compileSdkVersion 28
defaultConfig
applicationId "com.example.testfcm"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'




dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'


implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-iid:17.1.1'
implementation 'com.google.firebase:firebase-messaging:17.5.0'

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'









share|improve this question
















marked as duplicate by Zoe, Community Mar 27 at 13:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Make sure you have added google json file in your app and check package name in the file with your package name. and finally add FirebaseApp.initializeApp(this); in activity

    – rajahsekar
    Mar 27 at 12:59











  • Yes i added google json file.

    – PSP
    Mar 27 at 13:07











  • Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

    – ismail alaoui
    Mar 27 at 13:46











  • Finally i found a solutions. Just you need to add single line code in project build.gradle file i.e., mavenLocal();

    – PSP
    Mar 28 at 7:20

















-1
















This question already has an answer here:



  • Default FirebaseApp is not initialized

    26 answers



FCM (Firebase Cloud Messaging) initialize issue



I started working on FCM module, I fallowed as per the firebase guidelines. i'm getting two exceptions like RuntimeException and IllegalStateException. Firebase init default but why and what is the issue in FCM.



1. From Android Studio tools -> Firebase -> Cloud Messaging.



2. I fallowed Set up Firebase Cloud Mesasging.



I fallowed below link:



https://firebase.google.com/docs/cloud-messaging/android/client



App : Build.gradle



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:17.4.0'
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'



Project : Build.gradle



buildscript 
repositories
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.1.0'

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



allprojects
repositories
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir



In MainActivity.class, i trying to get token but app crashes.



 public class MainActivity extends AppCompatActivity 

public static final String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String tokenId = FirebaseInstanceId.getInstance().getToken(); //Crashes in this line
Log.d("SH", tokenId);




in logcat i got two exceptions



 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package PID: 29368
java.lang.RuntimeException: Unable to start activity ComponentInfocom.package.testfcm/com.package.MainActivity: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2861)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:1)
at com.package.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7032)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1236)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6626) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) 


Finally i found solutions, Now i able to get FCM Token.



In project build.gradle file you need add single line code code i.e., mavenLocal().



Fallow as per the below solutions cross check the project : build.gradle file and app : build.gradle file.



Project : build.gradle



buildscript 
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'

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



allprojects
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir




App : build.gradle



apply plugin: 'com.android.application'


android
compileSdkVersion 28
defaultConfig
applicationId "com.example.testfcm"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'




dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'


implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-iid:17.1.1'
implementation 'com.google.firebase:firebase-messaging:17.5.0'

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'









share|improve this question
















marked as duplicate by Zoe, Community Mar 27 at 13:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Make sure you have added google json file in your app and check package name in the file with your package name. and finally add FirebaseApp.initializeApp(this); in activity

    – rajahsekar
    Mar 27 at 12:59











  • Yes i added google json file.

    – PSP
    Mar 27 at 13:07











  • Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

    – ismail alaoui
    Mar 27 at 13:46











  • Finally i found a solutions. Just you need to add single line code in project build.gradle file i.e., mavenLocal();

    – PSP
    Mar 28 at 7:20













-1












-1








-1









This question already has an answer here:



  • Default FirebaseApp is not initialized

    26 answers



FCM (Firebase Cloud Messaging) initialize issue



I started working on FCM module, I fallowed as per the firebase guidelines. i'm getting two exceptions like RuntimeException and IllegalStateException. Firebase init default but why and what is the issue in FCM.



1. From Android Studio tools -> Firebase -> Cloud Messaging.



2. I fallowed Set up Firebase Cloud Mesasging.



I fallowed below link:



https://firebase.google.com/docs/cloud-messaging/android/client



App : Build.gradle



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:17.4.0'
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'



Project : Build.gradle



buildscript 
repositories
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.1.0'

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



allprojects
repositories
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir



In MainActivity.class, i trying to get token but app crashes.



 public class MainActivity extends AppCompatActivity 

public static final String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String tokenId = FirebaseInstanceId.getInstance().getToken(); //Crashes in this line
Log.d("SH", tokenId);




in logcat i got two exceptions



 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package PID: 29368
java.lang.RuntimeException: Unable to start activity ComponentInfocom.package.testfcm/com.package.MainActivity: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2861)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:1)
at com.package.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7032)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1236)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6626) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) 


Finally i found solutions, Now i able to get FCM Token.



In project build.gradle file you need add single line code code i.e., mavenLocal().



Fallow as per the below solutions cross check the project : build.gradle file and app : build.gradle file.



Project : build.gradle



buildscript 
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'

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



allprojects
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir




App : build.gradle



apply plugin: 'com.android.application'


android
compileSdkVersion 28
defaultConfig
applicationId "com.example.testfcm"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'




dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'


implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-iid:17.1.1'
implementation 'com.google.firebase:firebase-messaging:17.5.0'

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'









share|improve this question

















This question already has an answer here:



  • Default FirebaseApp is not initialized

    26 answers



FCM (Firebase Cloud Messaging) initialize issue



I started working on FCM module, I fallowed as per the firebase guidelines. i'm getting two exceptions like RuntimeException and IllegalStateException. Firebase init default but why and what is the issue in FCM.



1. From Android Studio tools -> Firebase -> Cloud Messaging.



2. I fallowed Set up Firebase Cloud Mesasging.



I fallowed below link:



https://firebase.google.com/docs/cloud-messaging/android/client



App : Build.gradle



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:17.4.0'
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'



Project : Build.gradle



buildscript 
repositories
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.1.0'

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



allprojects
repositories
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir



In MainActivity.class, i trying to get token but app crashes.



 public class MainActivity extends AppCompatActivity 

public static final String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String tokenId = FirebaseInstanceId.getInstance().getToken(); //Crashes in this line
Log.d("SH", tokenId);




in logcat i got two exceptions



 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package PID: 29368
java.lang.RuntimeException: Unable to start activity ComponentInfocom.package.testfcm/com.package.MainActivity: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2861)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.package. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:1)
at com.package.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7032)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1236)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6626) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) 


Finally i found solutions, Now i able to get FCM Token.



In project build.gradle file you need add single line code code i.e., mavenLocal().



Fallow as per the below solutions cross check the project : build.gradle file and app : build.gradle file.



Project : build.gradle



buildscript 
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()


dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'

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



allprojects
repositories
mavenLocal() //This is the line you need to add
google()
jcenter()




task clean(type: Delete)
delete rootProject.buildDir




App : build.gradle



apply plugin: 'com.android.application'


android
compileSdkVersion 28
defaultConfig
applicationId "com.example.testfcm"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'




dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'


implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-iid:17.1.1'
implementation 'com.google.firebase:firebase-messaging:17.5.0'

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'




This question already has an answer here:



  • Default FirebaseApp is not initialized

    26 answers







java android firebase android-studio android-developer-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 7:31







PSP

















asked Mar 27 at 12:30









PSPPSP

145 bronze badges




145 bronze badges





marked as duplicate by Zoe, Community Mar 27 at 13:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Zoe, Community Mar 27 at 13:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Zoe, Community Mar 27 at 13:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Make sure you have added google json file in your app and check package name in the file with your package name. and finally add FirebaseApp.initializeApp(this); in activity

    – rajahsekar
    Mar 27 at 12:59











  • Yes i added google json file.

    – PSP
    Mar 27 at 13:07











  • Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

    – ismail alaoui
    Mar 27 at 13:46











  • Finally i found a solutions. Just you need to add single line code in project build.gradle file i.e., mavenLocal();

    – PSP
    Mar 28 at 7:20

















  • Make sure you have added google json file in your app and check package name in the file with your package name. and finally add FirebaseApp.initializeApp(this); in activity

    – rajahsekar
    Mar 27 at 12:59











  • Yes i added google json file.

    – PSP
    Mar 27 at 13:07











  • Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

    – ismail alaoui
    Mar 27 at 13:46











  • Finally i found a solutions. Just you need to add single line code in project build.gradle file i.e., mavenLocal();

    – PSP
    Mar 28 at 7:20
















Make sure you have added google json file in your app and check package name in the file with your package name. and finally add FirebaseApp.initializeApp(this); in activity

– rajahsekar
Mar 27 at 12:59





Make sure you have added google json file in your app and check package name in the file with your package name. and finally add FirebaseApp.initializeApp(this); in activity

– rajahsekar
Mar 27 at 12:59













Yes i added google json file.

– PSP
Mar 27 at 13:07





Yes i added google json file.

– PSP
Mar 27 at 13:07













Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

– ismail alaoui
Mar 27 at 13:46





Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

– ismail alaoui
Mar 27 at 13:46













Finally i found a solutions. Just you need to add single line code in project build.gradle file i.e., mavenLocal();

– PSP
Mar 28 at 7:20





Finally i found a solutions. Just you need to add single line code in project build.gradle file i.e., mavenLocal();

– PSP
Mar 28 at 7:20












2 Answers
2






active

oldest

votes


















0














Try this way.




In Android Studio GO TO TOOLS Menu.


Then Select Firebase Option.


Provide your firebase enabled google account id-password.


From right side tab select Cloud Messaging.


Then click on setup firebase messaging .


Follow mension steps over there.






share|improve this answer
































    0














    I can see from your code that you are getting Firebase instance before it had to be initialized. You have to first initialize it then get token using getInstance().



    FirebaseApp.initializeApp(this);


    Or try the way google documents shows for getting token



    FirebaseInstanceId.getInstance().getInstanceId()
    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>()
    @Override
    public void onComplete(@NonNull Task<InstanceIdResult> task)
    if (!task.isSuccessful())
    Log.w(TAG, "getInstanceId failed", task.getException());
    return;


    // Get new Instance ID token
    String token = task.getResult().getToken();


    Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();

    );





    share|improve this answer



























    • Check updated answer

      – Abid Khan
      Mar 27 at 13:13











    • Yes i checked above answer still getting same exceptions and same crashes.

      – PSP
      Mar 27 at 13:20



















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try this way.




    In Android Studio GO TO TOOLS Menu.


    Then Select Firebase Option.


    Provide your firebase enabled google account id-password.


    From right side tab select Cloud Messaging.


    Then click on setup firebase messaging .


    Follow mension steps over there.






    share|improve this answer





























      0














      Try this way.




      In Android Studio GO TO TOOLS Menu.


      Then Select Firebase Option.


      Provide your firebase enabled google account id-password.


      From right side tab select Cloud Messaging.


      Then click on setup firebase messaging .


      Follow mension steps over there.






      share|improve this answer



























        0












        0








        0







        Try this way.




        In Android Studio GO TO TOOLS Menu.


        Then Select Firebase Option.


        Provide your firebase enabled google account id-password.


        From right side tab select Cloud Messaging.


        Then click on setup firebase messaging .


        Follow mension steps over there.






        share|improve this answer













        Try this way.




        In Android Studio GO TO TOOLS Menu.


        Then Select Firebase Option.


        Provide your firebase enabled google account id-password.


        From right side tab select Cloud Messaging.


        Then click on setup firebase messaging .


        Follow mension steps over there.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 12:37









        JigarJigar

        667 bronze badges




        667 bronze badges


























            0














            I can see from your code that you are getting Firebase instance before it had to be initialized. You have to first initialize it then get token using getInstance().



            FirebaseApp.initializeApp(this);


            Or try the way google documents shows for getting token



            FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>()
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task)
            if (!task.isSuccessful())
            Log.w(TAG, "getInstanceId failed", task.getException());
            return;


            // Get new Instance ID token
            String token = task.getResult().getToken();


            Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();

            );





            share|improve this answer



























            • Check updated answer

              – Abid Khan
              Mar 27 at 13:13











            • Yes i checked above answer still getting same exceptions and same crashes.

              – PSP
              Mar 27 at 13:20















            0














            I can see from your code that you are getting Firebase instance before it had to be initialized. You have to first initialize it then get token using getInstance().



            FirebaseApp.initializeApp(this);


            Or try the way google documents shows for getting token



            FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>()
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task)
            if (!task.isSuccessful())
            Log.w(TAG, "getInstanceId failed", task.getException());
            return;


            // Get new Instance ID token
            String token = task.getResult().getToken();


            Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();

            );





            share|improve this answer



























            • Check updated answer

              – Abid Khan
              Mar 27 at 13:13











            • Yes i checked above answer still getting same exceptions and same crashes.

              – PSP
              Mar 27 at 13:20













            0












            0








            0







            I can see from your code that you are getting Firebase instance before it had to be initialized. You have to first initialize it then get token using getInstance().



            FirebaseApp.initializeApp(this);


            Or try the way google documents shows for getting token



            FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>()
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task)
            if (!task.isSuccessful())
            Log.w(TAG, "getInstanceId failed", task.getException());
            return;


            // Get new Instance ID token
            String token = task.getResult().getToken();


            Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();

            );





            share|improve this answer















            I can see from your code that you are getting Firebase instance before it had to be initialized. You have to first initialize it then get token using getInstance().



            FirebaseApp.initializeApp(this);


            Or try the way google documents shows for getting token



            FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>()
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task)
            if (!task.isSuccessful())
            Log.w(TAG, "getInstanceId failed", task.getException());
            return;


            // Get new Instance ID token
            String token = task.getResult().getToken();


            Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();

            );






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 27 at 13:13

























            answered Mar 27 at 12:35









            Abid KhanAbid Khan

            1,2642 gold badges12 silver badges36 bronze badges




            1,2642 gold badges12 silver badges36 bronze badges















            • Check updated answer

              – Abid Khan
              Mar 27 at 13:13











            • Yes i checked above answer still getting same exceptions and same crashes.

              – PSP
              Mar 27 at 13:20

















            • Check updated answer

              – Abid Khan
              Mar 27 at 13:13











            • Yes i checked above answer still getting same exceptions and same crashes.

              – PSP
              Mar 27 at 13:20
















            Check updated answer

            – Abid Khan
            Mar 27 at 13:13





            Check updated answer

            – Abid Khan
            Mar 27 at 13:13













            Yes i checked above answer still getting same exceptions and same crashes.

            – PSP
            Mar 27 at 13:20





            Yes i checked above answer still getting same exceptions and same crashes.

            – PSP
            Mar 27 at 13:20



            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현