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
Related
I am trying to add fabric to my project but there is no where to provide the api key or secret on fabric.io?
Is this ok?
apply plugin: 'io.fabric'
`Please add maven and dependencies in project-level build.gradle
buildscript {
repositories {
// ...
// Add repository
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
// ...
// Check for v3.1.2 or higher
classpath 'com.google.gms.google-services:4.2.0'
// Add dependency
classpath 'io.fabric.tools:gradle:1.28.1'
}
}
allprojects {
// ...
repositories {
// ...
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
In your app-level build.gradle,add plugin and dependencies :
apply plugin: 'io.fabric'
dependencies {
// ...
// Check for v11.4.2 or higher
implementation 'com.google.firebase:firebase-core:16.0.8'
// Add dependency
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.0'
}
Follow below link https://firebase.google.com/docs/crashlytics/get-started?platform=android . Add your project into Firebase Console.
I want to use Segment (with Firebase) into my NativeScript app. So I must follow this instructions : https://segment.com/docs/destinations/firebase but I must modify two files : the Module-level build.gradle :
buildscript {
dependencies {
// Add these lines
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.segment.analytics.android.integrations:firebase:+'
}
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
and the Project-level build.gradle :
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
// Add this line
maven { url 'https://maven.google.com' }
}
}
But with NativeScript I have only one build.gradle. So, how can I implement this lines in gradle ?
Thanks !
I know this question is old but they may help someone in the future. Nativescript Docs aren't the best and this worked for me so it MAY not work for you.
This applies for Plugins and Regular Apps.
Buildscript Gradle.
App_Resources/Android/buildscript.gradle
PLUGINS buildscript.gradle
repositories {
// Add this line
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.google.gms:google-services:3.1.0'
}
App Grade
PLUGINS include.gradle
App_Resources/Android/app.gradle
dependencies {
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.segment.analytics.android.integrations:firebase:+'
}
apply plugin: 'com.google.gms.google-services'
HOWEVER
The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.https://docs.gradle.org/current/userguide/java_library_plugin.html
You can also write this as
App Grade
PLUGINS include.gradle
App_Resources/Android/app.gradle
dependencies {
implementation 'com.segment.analytics.android:analytics:4.+'
implementation 'com.segment.analytics.android.integrations:firebase:+'
}
i've been working with firebase to access an activity on my project. Everything works fine, no compilation errors. However after i go to tools > firebase i can connect to my app easily, however when i try to click Add Real time database it shows me this:
build.gradle will include these new dependencies:
compile 'com.google.firebase:firebase-database:16.0.1:15.0.0'
Since compile is deprecated i use implementation, and when i do
Implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
i get the following error Failed to resolve: firebase-database-15.0.0
and my sync fails.
Change Root Gradle to
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
}
}
allprojects {
// ...
repositories {
// ...
google() // Google's Maven repository
}
}
And App Gradle To
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Hope This May Help You
add jcenter() in your project-level gradle.
allprojects {
repositories {
google()
jcenter()
}
}
and keep remaining as #Tomin B said.
I still have this error inspite of me adding
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile "com.google.android.gms:play-services-gcm:11.8.0" to the build.gradle(app).Please help me resolve this problem.
First, add rules to your root-level build.gradle file, to include the google-services plugin and the Google's Maven repository:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.2.0' // google-services
plugin
}
}
allprojects {
// ...
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Then, in your module Gradle file (usually the app/build.gradle), add the
apply plugin line at the bottom of the file to enable the Gradle plugin:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:11.8.0'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
You may need to make sure that your activity is importing the Firebase Auth module.
In the .java file for your activity (eg. Login.java):
import com.google.firebase.auth.FirebaseAuth;
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