Getting error try to connect firebase - android

Hellow all,
I try to connect firebase to my android app but I'm getting this error
that was triggered I'm tried to sign in to firebase using the assistant tool. I'm tried several solutions here in StackOverflow. but It does not work for me.
this the gradle build project
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here is Gradle build Module
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.gpacalc.shannirmala.gpacalculator"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.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'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:27.1.1'
}

If you are referring firebase the first time then follow the manual setup because its increase your knowledge second time you can use the assistant tool.
Add Following dependency in Project level build.gradle file like bellow
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.0' // google-services plugin
}
Then after apply plugin in your app level build.gradle at bottom of your dependency section and also add firebase dependency in dependency section like bellow.
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support:design:26.+'
implementation 'com.android.support:cardview-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
implementation 'com.android.support:support-vector-drawable:26.1.0'
compile 'com.android.support:support-v4:26.+'
compile 'com.google.firebase:firebase-core:12.0.0'
compile 'com.google.firebase:firebase-auth:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
And Finally, put google-services.json file in app directory which downloaded from your firebase console after creating firebase project for your application.
How to create Firebase Project on console?

Related

How to fix "Could not find method" error?

I'm working on home work on Android studio, every thing was Ok, and I shut down my pc till next day, when i opened android studio i found this error message
ERROR: Could not find method implementation() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13-beta-3'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
// Displaying images
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
// Realtime database
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.android.support:support-v4:28.0.0'
}
Build file App Level :
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.appname"
minSdkVersion 15
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'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-vector-drawable:28.0.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'
//Add others below
}
Build file for Project Level :
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// 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
}
After having the same as above, you perform clean and then rebuild.
This error because of Glide library:
add following dependency too with glide dependency:
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
also if you are using androidx then you need to add :
annotationProcessor 'androidx.annotation:annotation:1.0.2'
Hope it will helps you.
This happens because the buildscript dependencies are outdated; update them to the current version, then it will know about implementation() and api() - or just use previous compile().
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
That version number always equals the version number of Android Studio; eg. build-tools 3.4.1 requires Android Studio 3.4.1 to build... updating the whole installation should automatically fix it.

Problem with the Gradle files. I have already connected the project to Firebase and now I am trying to add Google map

My project is connected to Firebase (Database) and now I am tring to add Google map. When I add one of the dependencies I get an error message while the sync.
It says something about using different version etc.
HELP !!
Description:
After I added this line to the app gradle file:
implementation 'com.google.android.gms:play-services-maps:16.0.0'
I got this error:
The library com.google.android.gms:play-services-base is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
with out the line that I have added everything is fine.
app gradle code:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.rotem.bepart_appproject"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
**implementation 'com.google.android.gms:play-services-maps:16.0.0'**
}
my project gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.1'
// 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
}
To solve this, please change the following lines of code:
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
**implementation 'com.google.android.gms:play-services-maps:16.0.0'**
to
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
Keeping the same version for all Firebase dependencies is now anti-pattern.

Multi Dex issue with Google AdMobs and Firebase analytics in Android

I am working on Android application where I am integrating Firebase Analytics and Google AdMobs. I am getting Multi Dex issue if I am using both together, independently both are working if I am not using other one Gradle link. I have used many solutions available on this platform, but nothing works for me.
I am putting my Gradle files along with the error which I am getting on compile time.
App Level Gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "fxxxxxipes"
minSdkVersion 21
multiDexEnabled true
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'com.android.support:cardview-v7:28.0.0'
compile 'com.parse:parse-android:1.16.3'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile project(':simplecropimagelib_')
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.makeramen:roundedimageview:2.3.0'
compile 'cn.ziyeyouhu.android:sweet-alert-dialog:1.0'
compile 'com.karumi:dexter:4.1.0'
implementation 'com.android.support:design:28.0.0'
compile 'com.parse:parsefacebookutils-v4-android:1.10.4#aar'
compile 'com.facebook.android:facebook-android-sdk:4.29.0'
compile fileTree(include: 'ParseFacebookUtilsV4-*.jar', dir: 'libs')
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:multidex:1.0.1'
compile 'com.mikhaellopez:circularimageview:3.0.2'
compile('com.crashlytics.sdk.android:crashlytics:2.9.6#aar') {
transitive = true;
}
implementation 'com.google.android.gms:play-services-ads:17.1.1'
implementation 'com.google.firebase:firebase-core:16.0.4'
}
Project Level Gradle File:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
// google()
maven {
url "https://maven.google.com"
}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Error which I am getting on Console:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Solution which I am currently using to fix this issue but still error is coming, I am using it in my Application Class:
MultiDex.install(this);
For me,
multiDex problem is always version conflict problem.
So in my opinion, don't need to install MultiDex and just try to keep same version of every gradles.
I have solved my problem thats why want to share for others. It was giving me a Dex file issue because for Analytics I was using Firebase and for Admobs I was using Google Libraries. Same features & functionality of Admobs is also available in firebase and integrated also. So now I am using now Firebase libraries only and it is now not giving any Dex issue:
implementation 'com.google.firebase:firebase-ads:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.4'

Gradle build fails because of firebase-auth dependency

I have updated the firebase-auth dependency version but gradle build always fails. It was working fine for 16.0.1
Error Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.2.
app level gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.dell.pitchpls"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.2'
//implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:3.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.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'
Project level gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.google.gms:google-services:4.0.1'
// 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
}
The problem is resolved following this question. Just had to uncheck the offline work in setting/gradle
Try These steps:
Open Module setting of the application
Under Dependencies tab click on '+' symbol and add dependency manually a
Click on apply.
Firebase Documentation
If you visit this link and scroll down to add dependency section, you will find out that gradle dependency version is 16.0.1 only
Also, to avoid such errors, let Android Studio do automatically for you.
For this, in Android Studio, go to:
Tools-->Firebase (This will open a Firebase Assistant)
Now choose your category like Authentication,Analytics,Cloud Messaging,etc --> Click on "Setup your category" and proceed with the steps mentioned there. It will automatically add all the gradle files and generated JSON file.

Dependency collision between play-services-map and firebase

Im trying to add firebase to a project that i already started, But in the build.gradle (app) i am having a dependency collision between play-services-maps and firebase, i looked everywhere and tried changing the version number but still not working.
here is the build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.android.tencho.test"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
//testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services:15.0.1'
// implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.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'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.google.firebase:firebase-core:16.0.0'
// //Firebase Auth
implementation 'com.google.firebase:firebase-auth:16.0.1'
// //FirebaseUI Auth
compile 'com.firebaseui:firebase-ui-auth:3.3.0'
}
apply plugin: 'com.google.gms.google-services'
Build.gradle (project level)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// The google-services plugin has 2 main functions:
// 1) Process the google-services.json file and produce Android resources that can be used in your
// application's code
// 2) Add dependencies for basic libraries required for the services you have enabled. This step requires
// that the apply plugin: 'com.google.gms.google-services' line be at the bottom of your app/build.gradle file
// so that no dependency collisions are introduced.
classpath 'com.google.gms:google-services:4.0.1'
// 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
}
You are using inconsistent version.
Let me tell you simple example.
If you are using google play services 11.8.0, then firebase should also be in same version..
compile 'com.google.android.gms:play-services:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.firebase:firebase-crash:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
So the main thing to be noted is, you are using inconsistent versions.

Categories

Resources