I am trying to add Firebase SDK to Android project.
buildscript {
repositories {
google()
}
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google() // Google's Maven repository
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
error message:
> Build file 'C:\\Users\\Admin1\\AndroidStudioProjects\\MyApplication\\build.gradle' line: 7
> A problem occurred evaluating root project 'My Application'.
> Could not find method plugins() for arguments \[build_arjjpsftc7rcjw6ntcnbana8l$\_run_closure1$\_closure3#22dd2f7f\] on object of type org.gradle.api.internal.initialization.DefaultScriptHandler.
You should move the plugins{} block to top of your file and outside of your buildscript{} block
buildscript {
repositories {
google()
}
}
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
In my application, I want to use firebase Crashlytics and for this, I added below codes into my application.
I added this codes step by step from google document!
I added below codes but when sync application show me an error and not sync project.
Build.gradle (project) :
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.1.0'
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://dl.bintray.com/tapsellorg/maven' }
maven { url 'https://maven.google.com/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build.gradle (app) :
dependencies {
implementation 'com.google.android.gms:play-services-base:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
but when added this line apply plugin: 'com.google.gms.google-services' , when click on sync show me below error :
The library com.google.android.gms:play-services-base is being requested by various other libraries at [[11.0.2,11.0.2]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
How can I fix it?
build.gradle Module
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
// add the Firebase SDK for Google Analytics
// The app need this to init in Firebase console
implementation 'com.google.firebase:firebase-analytics:17.2.1'
// Add the Firebase SDK for Crashlytics.
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta01'
build.gradle Project
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta01'
You do not need fabric.io anymore, it is deprecated and will be available until March 31, 2020.
Take a look at this Project
and Video
if after all Firebase doesn't recognize the app, record an exception using this
recordException
in android studio 4.0 and above
project level gradle
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false // Google Services plugin
// Crashlytics Gradle plugin
id 'com.google.firebase.crashlytics' version '2.8.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.3.2')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-crashlytics'
}
I have followed the below steps to achieve adding the Firebase Crashlytics to the project,
1.Get the google-service json file and complete adding project to the firebase follow this link Firebase Console.
2.In project build.gradle file add the below code,
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
maven {
url 'https://maven.google.com'
}
}
dependencies {
// Check for v3.1.2 or higher
classpath 'com.google.gms:google-services:4.3.2'
// Add dependency
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
allprojects {
repositories {
maven {
url 'https://maven.google.com'
}
maven {
url 'https://maven.fabric.io/public'
}
}
}
3.Inside the app build.gradle file, add the below code,
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
and in dependencies add,
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
4.Induce the crash to check whether it gets reflected in the console in section crashlytics,
Crashlytics.getInstance().crash();
Hope it helps :)
To enter Firebase Crashlytics the first thing you need to do is follow these simple steps:
In app-> build.gradle:
apply plugin: 'io.fabric'
dependencies {
implementation "com.google.firebase:firebase-core:17.2.0"
// Add dependency
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
In general build.gradle:
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.31.2' // Crashlytics plugin
}
Obviously after that, insert the json file in your project folder to connect your app to Firebase
To do the first test and evaluate if everything is working properly, you don't need to initialize anything, because Crashlytics has the singleton. So go to the main screen of your app and not to Application (otherwise it won't work), and try this:
Crashlytics.getInstance().crash();
After doing the test, go to your app's Firebase panel and click on the Crashlytics button
Register your android app in firebase console and download google-play-services.json and paste under app in project directory.
Please follow below steps:
In project level build.gradle,add below dependency:
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.1'
In app level build.gradle,add below plugin:
apply plugin: 'com.google.firebase.crashlytics'
In project level build.gradle,add below dependency:
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
For checking,add below code to crash
Crashlytics.getInstance().crash();
You don't need any dependency or.jar file to add crashlytics in your app just follow below steps and let me know if you face any error.
Add the dependency on Google Analytics for Firebase to your app-level build.gradle file:
implementation 'com.google.firebase:firebase-core:16.0.6'
After this, Declare the com.google.firebase.analytics.FirebaseAnalytics object at the top of your activity:
private FirebaseAnalytics mFirebaseAnalytics;
Then initialize it in the onCreate() method:
// Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
That's it for more info refer to official docs of Firebase on How to integrate crashlytics (https://firebase.google.com/docs/analytics/android/start)
Note : mismatching of firebase libraries can give you gradle compilation errors
in your build.gradle add:
buildscript {
repositories {
// Add Google's Maven repository.
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
// ...
// Add the Google Services plugin (check for v3.1.2 or higher).
classpath 'com.google.gms:google-services:4.3.3'
// Add the Fabric Crashlytics plugin.
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
Add your app level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
// Add the Fabric plugin.
apply plugin: 'io.fabric'
dependencies {
// ...
// (Recommended) Add the Google Analytics dependency.
implementation 'com.google.firebase:firebase-analytics:17.2.3'
// Add the Firebase Crashlytics dependency.
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
Change min Sdk version to 16 in app level build.gradle.
You can go through this link for detailed description of how to connect to crashlytics http://blogssolutions.co.in/android-app-add-firebase-crashlytics/
My build.gradle afer updating it look like this. And it gives me the error.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
}
android {
compileSdkVersion 21
buildToolsVersion '23.0.3'
}
allprojects {
repositories {
jcenter()
}
}
earlier it looks like this
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
And that gave me this error -
Error:Failed to find target with hash string 'Google Inc.:Google APIs:21' in:
/Users/abc/Library/Android/sdk
Open Android SDK Manager
Don't know how to to get it fix. Please help just try to run app with components
Also checked all the possible solution. Possible duplicate
failed to find target with hash string 'android-22'
Could not find method android() for arguments
Add the below lines in app build.gradle, not in your project top level build.gradle.
android {
compileSdkVersion 21
buildToolsVersion '23.0.3'
}
In the left pane, select 'Project' view. Under ProjectName/app/ you will find a build.gradle file. Add the above lines in that file, and remove it from your top level build.gradle file.
I reinstalled android studio, I am using the same project with android studio in another PC so the code is probably fine!
It is the full error:
Error:(23, 0) Could not find method android() for arguments [build_1z9k6ruj47plglocgqknjnoag$_run_closure3#133cf914] on root project 'allthingsvegan-android-9d296805dc64' of type org.gradle.api.Project.
Open File
The solutions I've found on the internet was including changing the code.. So they are not relevant to me
Thanks!!
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.2.0-beta1'
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
}
android {
buildToolsVersion '24.0.1'
}
It is the top-level build.gradle file.
In this file you can't use this block:
android {
buildToolsVersion '24.0.1'
}
Remove this block.
you need to apply the android plugin:
apply plugin: 'com.android.application'
this needs to be done after buildscript like this:
// 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.2.0-beta1'
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
}
apply plugin: 'com.android.application'
android {
buildToolsVersion '24.0.1'
}
uncomment android tag present in build.gradle(Project:android-start)
rebuild the gradle it asks to update .
Update the gradle then sync it works
I'm getting the duplicate entry error for abstractHttpContent.class which is part of app engine.
I'm using google app engine backend. I also have multidex enabled, without multidex it give me an method exceeded error.
here is my app gradle file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.joseph.googlesign_in"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile project(path: ':gsiBackend', configuration: 'android-endpoints')
compile project(':gsiBackend')
}
Here is my backend gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
compile 'com.google.appengine:appengine-endpoints:1.9.18'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
compile 'javax.servlet:servlet-api:2.5'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
The location of abstractHttpContent.class
It seems the error started after adding google play services to use google sign in.
Has anyone encountered this build error? Any advice on how to fix it?
Thanks
As we discuss, I believe Google play services 8.3 made some changes on the google signin system. You can check out here:
https://developers.google.com/android/guides/releases#november_2015_-_v83
So I suggest that you can try to use version 8.1.
The issue was with google play services.
Here is top level gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// 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
}
Change the following
From
classpath 'com.google.gms:google-services:1.5.0-beta2'
To
classpath 'com.google.gms:google-services:1.5.0'
Also the aapt.exe was timing out and displaying an error.
Ran the appt.exe file to make sure it was running and everything seems to be working now.
Tried to run the app with mulidex disabled and it still works
The issue was with google play services.
Here is my top level gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// 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
}
Change the following
From
classpath 'com.google.gms:google-services:1.5.0-beta2'
To
classpath 'com.google.gms:google-services:1.5.0'
Also the aapt.exe was timing out and displaying an error.
I ran the appt.exe file to make sure it was running and everything seems to be working now.
I also tried to run the app with mulidex disabled and it still works