I am facing this issue and seen some answers on this site but did not get any proper solution.
I have used previous version of Firebase which works fine but when I try to upgrade using Upgradation and update Firebase class to DatabaseReference it shows error and not working.
I am adding my manifest file entire code so please help me to resolve this issue.
Here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="firebasechat.com.firebasechat">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:name=".Activity.SimpleBlog"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Activity.RegisterActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
my Module app is given below.
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "firebasechat.com.firebasechat"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.volley:volley:1.0.0'
compile "com.google.firebase:firebase-database:11.0.0"
compile 'com.google.android.gms:play-services:11.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
and Project 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.3'
classpath 'com.google.gms:google-services:4.2.0'// Updated version of google service
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Below is my Activity.
public class RegisterActivity extends AppCompatActivity {
EditText username, password;
Button registerButton;
String user, pass;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
username = (EditText)findViewById(R.id.username);
password = (EditText)findViewById(R.id.password);
registerButton = (Button)findViewById(R.id.registerButton);
FirebaseApp.initializeApp(this);
registerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
user = username.getText().toString();
pass = password.getText().toString();
final ProgressDialog pd = new ProgressDialog(RegisterActivity.this);
pd.setMessage("Loading...");
pd.show();
String url = "https://pure-coda-174710.firebaseio.com/users.json";
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>(){
#Override
public void onResponse(String s) {
// Firebase reference = new Firebase("https://pure-coda-174710.firebaseio.com/users");
DatabaseReference reference = FirebaseDatabase.getInstance()
.getReferenceFromUrl("https://pure-coda-174710.firebaseio.com/users");
if(s.equals("null")) {
reference.child(user).child("password").setValue(pass);
Toast.makeText(RegisterActivity.this, "registration successful", Toast.LENGTH_LONG).show();
}
else {
try {
JSONObject obj = new JSONObject(s);
if (!obj.has(user)) {
reference.child(user).child("password").setValue(pass);
Toast.makeText(RegisterActivity.this, "registration successful", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(RegisterActivity.this, "username already exists", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
pd.dismiss();
}
},new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError volleyError) {
System.out.println("" + volleyError );
pd.dismiss();
}
});
RequestQueue rQueue = Volley.newRequestQueue(RegisterActivity.this);
rQueue.add(request);
}
});
}
}
In your SimpleBlog application class, initialize FirebaseApp in onCreate() method and remove it from RegisterActivity in order to have Firebase initialize into entire application, not just one Activity.
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
Also add apply plugin: 'com.google.gms.google-services' at the end of app gradle:
dependencies {
....
}
apply plugin: 'com.google.gms.google-services'
Plugin is required to process your json config from firebase and to avoid dependency collisions. You can read here for more details.
Spent literally a whole day. Finally, this was the solution.
Freaking 0 instead of 1 and you will not have to use the initialize firebaseapp or anything like that.
In Project gradle, use Google services: 4.0.0 and not 4.1.0.
Plus, apply plugin statement at the end is also not necessary in my experience.
(Hoping you have added firebase database from the tools => firebase assistant. Step 1 and step 2 are right and green. )
According to FirebaseApp documentation, you do not need to invoke this initialization, except that your app requires access to another Firebase project.
I invoked this initialization and sometime, user gets crash time to time when user opens my app, so I remove this line of code then everything works well. Be careful to invoke this initialization.
The capture of FirebaseApp documentation:
Update: below Exception will occur if you try to add this line [Some ads network requires this line, they also add some process in their AndroidManifest]
Failed to gain exclusive lock to the Firestore client's offline persistence. This generally means you are using Firestore from multiple processes in your app. Keep in mind that multi-process Android apps execute the code in your Application class in all processes, so you may need to avoid initializing Firestore in your Application class. If you are intentionally using Firestore from multiple processes, you can only enable offline persistence (i.e. call setPersistenceEnabled(true)) in one of them.
To fix it:
1) add below method in your Application class:
private boolean isMainProcess(Context context) {
if (null == context) {
return true;
}
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int pid = android.os.Process.myPid();
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (APPLICATION_ID.equals(processInfo.processName) && pid == processInfo.pid) {
return true;
}
}
return false;
}
2) Wrap onCreate of your Application
#Override
public void onCreate() {
super.onCreate();
if (!isMainProcess(this)) {
FirebaseApp.initializeApp(this);
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.build();
FirebaseFirestore.getInstance().setFirestoreSettings(settings);
// other things
return;
}
// other things
}
UPDATE: Sometime, my app throws below exception
Unable to create application My Application Class : java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process MY_APPLICATION_ID. Make sure to call FirebaseApp.initializeApp(Context) first.
To Fix It: let update onCreate method:
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
boolean isMain = isMainProcess(this);
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(isMain).build();
FirebaseFirestore.getInstance().setFirestoreSettings(settings);
if (!isMain) {
// other things
return;
}
// other things
}
Got same problem and solved this way:
in activity:
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
in app's gradle (at the end of file):
dependencies {
....
}
apply plugin: 'com.google.gms.google-services'
is project's gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.0.0'
}
I had this same issue some time ago.
You're trying to get an instance of Firebase without initialize it.
Please add this line of code before you try to get an instance of
Firebase:
Just import latest version firebase and google play services.
Recent update version (example):
add to these lines build.gradle
dependencies {
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
}
apply plugin: 'com.google.gms.google-services'
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
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
}
thats all. Enjoy your coding.
First thing first: Project config JSON's may go wrong/obsolete mostly on upgrade of Firebase.
Go to Tools->Firebase->Cloud Messaging->Set up firebase cloud messaging.
Even if you have done that in the past, it's worth the double check here as things get updated from time to time. I sync-ed my project and it solved the issue.
As for calling FirebaseApp.initializeApp, it is not necessary, at least not for FCM. See the FCM documentations.
Furthermore, if it return null it means that it fails, so calling it before calling getInstance won't do.
Note that this is the getInstance of FirebaseInstanceId:
public static FirebaseInstanceId getInstance() {
return getInstance(FirebaseApp.getInstance());
}
Where on the other hand:
#Nullable
public static FirebaseApp initializeApp(Context var0) {
Object var1 = sLock;
synchronized(sLock) {
if (zzf.containsKey("[DEFAULT]")) {
return getInstance();
} else {
FirebaseOptions var2;
return (var2 = FirebaseOptions.fromResource(var0)) == null ? null : initializeApp(var0, var2);
}
}
}
It means that it's if initializeApp returns null, you probably have issues with the configurations. At least - worth checking. To know where you are at, put a breakpoint at some point where Context is visible, and try to evaluate FirebaseApp.initialize(context) to make sure it does not return null.
Please downgrade google service plugin from version 4.1.0 to 4.0.1 in project's build.gradle
classpath 'com.google.gms:google-services:4.0.1'
And add this code to onCreate()
FirebaseApp.initializeApp(this);
it worked for me.
I had the same problem too and i noticed that this problem only occured to me when i added Firebase Storage dependency.
So as i am using API 28, I made sure that all firebase dependencies have same import version i.e 16.0.5as of the storage dependency.
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
I updated my gradle version to
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
And i added the line below the app module
apply plugin: 'com.google.gms.google-services'
then it worked for me.
To prevent this error, one need to follow all the steps involved in setting up Firebase for android https://firebase.google.com/docs/android/setup
I got the same error as I forgot to follow two steps and fixed it by
1) adding classpath 'com.google.gms:google-services:4.2.0' to project level gradle build file.
2) adding apply plugin: 'com.google.gms.google-services' to module level gradle build file.
update the gradle main classpath 'com.google.gms:google-services:4.2.0'
No need to add anything in Application class or call initializeApp() for firebase. After adding firebase capabilities to your app through Tools -> Firebase - > (Any functionality) -> Make sure step 1 and 2 is green and checked.
Go to project gradle file and use
classpath 'com.google.gms:google-services:4.2.0'
that's it.
I didn't use FirebaseApp.initializeApp(Context) on my project.
It works for me. You should check your gradle files and be sure you implemented this lines:
add apply plugin: 'com.google.gms.google-services' into your gradle(app)
or
add this classpath 'com.google.gms:google-services:4.2.0' into your gradle(project).
I had the same problem , i Modified my Project build.gradle to be as follows
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.0'
....
}
then i added the line below into the app module
apply plugin: 'com.google.gms.google-services'
and it was solved
You are experiencing this error because of google updata, All you need is do the following
Change the following dependency from
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.1.0'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.0'
}
The difference is that google-services:4.1.0 should be changed to 4.0.0
Also you might be missing this plugin
apply plugin: 'com.google.gms.google-services'
implementation 'com.google.firebase:firebase-core:16.0.6
If error FirebaseApp.initializeApp(Context) add "mavenCentral" in your build.gradle
enter code here repositories {google() jcenter() mavenCentral() }
Try to downgrade or upgrade the Gradle version.
For example, your build.gradle have :
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
Change to
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
Try adding your app to firebase console and updating the new google-services.json file in your application. This worked for me, when I had tried to implement the app with the database and json file of another project.
After migration you have to update the dependencies to the new SDK, check this: https://stackoverflow.com/a/61681739/5279996
You are using very old method of firebase now you dont need to use
***FirebaseApp.initializeApp(context)***
remove this. then:
Just add Your App with package name to your firebase project download the google Json file
from this link here
add your package name and then copy the downloaded google json file in your “app” now Add
the instructed libraries into both app level and project level gradle. now just sync the
project and you are ready to use firebase.
When this error occurs, it's because you are not using the latest version of firebase dependencies.
Update all dependencies to the latest ones and you are good to go!
put these two lines in build.gradle ( app level )
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
( this picture taken from Firebase > Settings > Android App > Method of setting SDK
if it is correct , it will yeild error cannot find file 'google-services.json'
then you copy your google-service.json file that generated from
Firebase > Setting > Android App > Click "google-services.json" to genetate the file.
You do not have to worry about the path that you will save this file.
The error will show where do you need to save this file.
For example I save in app/ ( next to build.gradle (app level ))
Using Kotlin,
"Make sure to call FirebaseApp.initializeApp(Context) first in
Android"
this is an example for a correct Firebase Analytics initialization:
// declare_analytics
private lateinit var firebaseAnalytics: FirebaseAnalytics
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Obtain the FirebaseAnalytics instance.
firebaseAnalytics = Firebase.analytics
val parameters = Bundle().apply {
this.putString("level_name", "Jorgesys B. " + System.currentTimeMillis())
this.putInt("level_difficulty", 10)
}
firebaseAnalytics.setDefaultEventParameters(parameters)
}
Related
Non-programmer newbie here. I have issues integrating Flurry Analytics into my first Godot Android project (and will do it for iOS after too). I've done everything as instructed I believe but I keep getting errors when exporting to Android and this is the latest one I got;
> Task :compileDebugJavaWithJavac FAILED
C:\Users\Acer\Desktop\Godot\game\android\build\src\com\godot\game\GodotApp.java:48: error: package FlurryAgent does not exist
new FlurryAgent.Builder()
^
1 error
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Did I paste any codes at the wrong files? I pasted the arr into the build.gradle file within the Android folder of my Godot project here;
apply from: 'config.gradle'
buildscript {
apply from: 'config.gradle'
repositories {
google()
mavenCentral()
//CHUNK_BUILDSCRIPT_REPOSITORIES_BEGIN
//CHUNK_BUILDSCRIPT_REPOSITORIES_END
}
dependencies {
classpath libraries.androidGradlePlugin
classpath libraries.kotlinGradlePlugin
//CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
//CHUNK_BUILDSCRIPT_DEPENDENCIES_END
}
}
apply plugin: 'com.android.application'
allprojects {
repositories {
google()
mavenCentral()
//CHUNK_ALLPROJECTS_REPOSITORIES_BEGIN
//CHUNK_ALLPROJECTS_REPOSITORIES_END
// Godot user plugins custom maven repos
String[] mavenRepos = getGodotPluginsMavenRepos()
if (mavenRepos != null && mavenRepos.size() > 0) {
for (String repoUrl : mavenRepos) {
maven {
url repoUrl
}
}
}
}
}
dependencies {
implementation 'com.flurry.android:analytics:13.1.0#aar'
implementation libraries.supportCoreUtils
implementation libraries.kotlinStdLib
implementation libraries.v4Support
if (rootProject.findProject(":lib")) {
implementation project(":lib")
} else if (rootProject.findProject(":godot:lib")) {
implementation project(":godot:lib")
} else {
// Custom build mode. In this scenario this project is the only one around and the Godot
// library is available through the pre-generated godot-lib.*.aar android archive files.
debugImplementation fileTree(dir: 'libs/debug', include: ['*.jar', '*.aar'])
releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
}
And I then pasted the initialising calls to the GodotApp.java file in the src folder of the project. This is where I suspect where I got it wrong;
package com.godot.game;
import org.godotengine.godot.FullScreenGodotApp;
import android.os.Bundle;
/**
* Template activity for Godot Android custom builds.
* Feel free to extend and modify this class for your custom logic.
*/
public class GodotApp extends FullScreenGodotApp {
#Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.GodotAppMainTheme);
super.onCreate(savedInstanceState);
new FlurryAgent.Builder()
.withLogEnabled(true)
.build(this, "9NZTG7YG8GZBP9SY7K89");
}
}
Appreciate it if you can enlighten this clueless newbie. I have very little programming knowledge so certain things are still very foreign to me.
UPDATE:
I've decided to abandon Flurry and just use Firebase instead since there's much more information about it available online. Implemented it to my project within minutes.
In your app's build.gradle file, you need to add Flurry dependency.
// In your main app's Gradle config file:
repositories {
mavenCentral()
}
dependencies {
// Recommended to add Google Play Services
implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0'
// Required for Flurry Analytics integration
implementation 'com.flurry.android:analytics:13.1.0'
}
and in your codes, add
import com.flurry.android.FlurryAgent;
I followed the tutorial exactly (https://firebase.google.com/docs/crashlytics/get-started?authuser=1&platform=android#android) and still can't see my app on firebase Crashlytics. here's my configuration:
in root build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath 'io.fabric.tools:gradle:1.31.0'
}
in app build.gradle
...
apply plugin: "io.fabric"
...
//Firebase
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-config:18.0.0'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
in Application
Fabric.with(this, Crashlytics());
I'm building and running the app on debug but nothing is happening, in the logs I see
I/CrashlyticsInitProvider: CrashlyticsInitProvider skipping initialization
I/CrashlyticsCore: Initializing Crashlytics Core 2.7.0.33
what could I be missing?
For anyone who is facing a similar issue, I have looked for many hours and eventually checked the merged manifest and figured there is a 3rd party library that was actually setting up their own Crashlytics config which overrides mine. So maybe look into that.
I eventually added this to my manifest:
<meta-data
tools:node="remove"
android:name="io.fabric.ApiKey"/>
Refer to the Firebase Crashlytics Docs.
Step 1: Add this code in your project level build.gradle file
buildscript {
repositories {
// Add the following repositories:
google() // Google's Maven repository
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
// ...
// Check for v3.1.2 or higher
classpath 'com.google.gms:google-services:4.3.0' // Google Services plugin
// Add dependency
classpath 'io.fabric.tools:gradle:1.31.0' // Crashlytics plugin
}
}
allprojects {
// ...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
Step 2 : Add this code in your app-level build.gradle file
apply plugin: 'io.fabric'
dependencies {
// ...
// Check for v11.4.2 or higher
implementation 'com.google.firebase:firebase-core:17.0.1'
// (Recommended) Add Analytics
implementation 'com.google.firebase:firebase-analytics:17.0.1'
// Add dependency
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
Make sure you have added google-services.json and running your app in physical device or emulator having google play services.
credit goes to firebase for creating such a helpful docs.
This is Zubair from Fabric/Firebase. Could you try to make individual build and run event on a brand new simulator (where they've not installed/ran this app before). If issue persist, reach out to us AT "support#fabric.io" and include app name/bundle id and firebase project id in the email.
I'm trying to use the sdk Firebase natively on Android but when I try to initialize Firebase using:
com.google.firebase.FirebaseApp.initializeApp(utils.ad.getApplicationContext();
I receive this error
System.err: Error: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process *******. Make sure to call FirebaseApp.initializeApp(Context) first.
in my app.gradle:
dependencies {
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile "com.google.android.gms:play-services-base:11.8.0"
}
can help me?
Add rules to platforms/android/build.gradle file, to include the google-services plugin and the Google's Maven repository:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.1' // google-services plugin
}
}
allprojects {
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Insert firebase dependencies to App_Resources/Android/app.gradle:
dependencies {
compile 'com.google.firebase:firebase-core:11.8.0'
//compile 'com.google.firebase:firebase-messaging:11.8.0'
//compile "com.google.android.gms:play-services-base:11.8.0"
// ...
}
And at the end of App_Resources/Android/app.gradle insert:
apply plugin: 'com.google.gms.google-services'
Finally, if you hit the error:
> File google-services.json is missing. The Google Services Plugin cannot function without it.
Copy manually the google-services.jsonfile:
cp app/App_Resources/Android/google-services.json platforms/android/app/google-services.json
Meanwhile, thank you so much for your reply #attdona :)
I solved by doing more or less what you did.
The only differences are that:
To use a dynamic build.gralde I created a hook to replace the
original one with mine to compile.
Always using a hook I copied
the file google-services.json from App_Resources/Android/ to
platforms/android/app
I am following the firebase assistant and video tutorial. I am receiving an error and it says that (see picture below)
Here is my code:
I had the same problems with Button, EditText, and View; but I resolved that by adding import statements. Is there any way import Firebase?
Just import com.google.firebase.database.FirebaseDatabase
Simply you goto Firebase Console and add your required dependecies like com.google.firebase:firebase-database:11.4.0 you have to add this line in your app/build.gradle
make sure have to add core dependency in app/build.gradle which is compile 'com.google.firebase:firebase-core:11.4.0'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-database:11.4.0'
compile 'com.google.firebase:firebase-core:11.4.0'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
in your build.gradle you've to add this snippet
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.0' // google-services
plugin
}
}
allprojects {
// ...
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Happy to help you
I followed all the steps on the docs to use Firebase Crash Reporting in my Android app (I use Android Studio and everything is up-to-date).
I used their own code to throw an exception to see if it works:
try {
throw new NullPointerException();
} catch (NullPointerException ex) {
FirebaseCrash.logcat(Log.ERROR, TAG, "NPE caught");
FirebaseCrash.report(ex);
}
And the console gives me this log:
E/MainActivity: NPE caught
V/FirebaseCrash: Firebase Crash Reporting is disabled.
Here is one 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.1.0'
// Firebase - Google Services 3.0.0
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is the other build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-N'
buildToolsVersion '24.0.0-rc2'
defaultConfig {
applicationId "com.app.test"
minSdkVersion 19
targetSdkVersion 'N'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
useProguard true
}
}
}
dependencies {
compile 'com.android.support:support-v4:24.0.0-alpha1'
compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
compile 'com.android.support:design:24.0.0-alpha1'
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-analytics:9.0.0'
compile 'com.google.firebase:firebase-crash:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.google.firebase:firebase-config:9.0.0'
compile 'com.google.firebase:firebase-invites:9.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
I also use:
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
FirebaseMessaging.getInstance().subscribeToTopic("news");
Log.d(TAG, "Subscribed to news topic");
I added all dependencies that I'll need, but I'm adding one by one and testing one by one, and Notifications works, Analytics: no idea, it takes about 24 hours to update, so until it does, I don't know if is working...
So, the thing is how can I enable it?
NOTE: I have all of the dependencies added including the crash and core ones, also the plugin and the classpath
Thank you in advanced.
Please note the following:
After adding the SDK you can try using:
FirebaseCrash.report(new Exception("My first Android non-fatal error"));
Errors take up to 20 minutes to show up in the Crash Reporting console. Check back to see your report there.
(It may seem obvious but) make sure you have:INTERNET and ACCESS_NETWORK_STATE permission.
Crash reporting was not working for me too after correctly setting it up in my App. To fix this I visited my developer console, API Manager, and enabled the "Mobile Crash and Performance Reporting API". To find out exactly where you need to do this follow the steps on this page.
If you follow the steps in the link above, the logcat that has the text "E/FirebaseCrashSenderServiceImpl: Error sending crash report" gives you a URL to where you must go in the console to enable crash reporting.
The FirebaseCrash is deprecated. The FirebaseCrashlytics.getInstance() should be used instead:
FirebaseCrashlytics.getInstance().log(message)
FirebaseCrashlytics.getInstance().recordException(throwable)
Source: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#add-logs
Add following code:
In Project-level build.gradle (/build.gradle):
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.0.0'
}
}
In App-level build.gradle (//build.gradle):
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
//Add following in In App-level build.gradle
compile 'com.google.firebase:firebase-crash:9.0.0'
Now sync your project,
Use following code in your activity to throw exception:
FirebaseCrash.report(new Exception("App Name : My first Android non-fatal error"));
check android crash reporting tutorial using firebase for complete guidance.
I had the same issue. Turns out I was missing dependency in my project gradle file. Try adding this. It should help.
buildscript {
repositories {
jcenter()
// ...
}
dependencies {
// ...
classpath 'com.google.firebase:firebase-plugins:1.0.5'
}
}
You should allow some time to show up. Even though the documentation says the errors will show up within 5 minutes, it can take up to 15-20 minutes. Also, you have to change your old modules to AndroidX by migrating it if you use native development. Finally, make sure that all the tools and plugins are added in the appropriate Gradle files.