Project level build.gradle not containing the appropriate code - firebase

I am trying to setup firebase for the first time and following a tutorial. I have to add this: classpath 'com.google.gms:google-services:4.3.12' to the project level build.gradle file under builscript->repositories but when I try to access the build.gradle file this is all I see:-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now, I am not sure if this is due to a new update and the format has changed, but I have peeked at project level build.gradle file of a different project before and this is not what I saw. (This is a complete new project nothing has been done to the file other than adding the google-services.json file)
Can anyone help me out here if I am missing anything?

It can be added via the plugins API:
plugins {
...
id 'com.google.gms.google-services' version '4.3.12' apply false
}
Then apply on the module level:
plugins {
...
id 'com.google.gms.google-services'
}

Related

How to automatically add the necessary dependencies in Android Studio?

I have a Kotlin Android Studio project I am making that integrates with Firebase. I added all the lines required listed in Firebase's instructions into build.gradle for both the Project level and the App level.
But this doesn't include any of the dependencies my project seems to need, I get an error when trying to build and these warnings:
The Declared Dependencies list for my app module only has the two Firebase dependencies, and not any of the dependencies as listed by the above warnings:
I noticed there are some dependencies I assume I need in All Modules:
Is there a way I can add those into my app module folder? I am not sure if that's how it works so let me know.
If this is not the way, please let me know how I can add all these required dependencies quickly onto my Project (preferrably without manually searching each one's repository url and such) so that I can Sync and Build without any errors.
The Gradle Sync was just now successful, here's what happened:
During the editing of the build.gradle files, Google Firebase's instructions were to add this line of code to the Project level's build.gradle file:
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
...
}
}
When Syncing the files through Gradle, an error occurred stating that settings.gradle was prefered to build.gradle, as it also contains repositories and dependencies. The fix was to remove the dependencyResolutionManagement code block in settings.gradle.
Here's what I did to fix all the Sync Warnings and Build errors:
Added the same dependencies found in settings.gradle to build.gradle in the Project level:
gradlePluginPortal()
google()
mavenCentral()
It did not work yet, so then I noticed you also need to add it under the allprojects code block. It will then look something like this:
buildscript {
repositories {
// Check that you have the following line (if not, add it):
gradlePluginPortal()
google() // Google's Maven repository
mavenCentral()
}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
gradlePluginPortal()
google() // Google's Maven repository
mavenCentral()
...
}
}
And that was all. After that the Gradle Sync took a long time this time and completed successfully without any errors, and the Build worked as well and ran fine as expected.

Type 'UploadMappingFileTask' property 'googleServicesResourceRoot' doesn't have a configured value

After updating the classpath I can no longer build a release version of the app.
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':app:uploadCrashlyticsMappingFileRelease' (type 'UploadMappingFileTask').
- Type 'UploadMappingFileTask' property 'googleServicesResourceRoot' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'googleServicesResourceRoot'.
2. Mark property 'googleServicesResourceRoot' as optional.
A problem was found with the configuration of task ':app:uploadCrashlyticsMappingFileRelease' (type 'UploadMappingFileTask').
- Type 'UploadMappingFileTask' property 'googleServicesResourceRoot' doesn't have a configured value.
I tried to read the changelog but no guidelines or documentation about it.
To fix it, the Google Services plugin should be applied before any Firebase plugin in /app/build.gradle.
This produces the error:
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
While this does not:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf
Note that com.google.gms.google-services is ABOVE com.google.firebase.crashlytics.
When you update to com.google.firebase:firebase-crashlytics-gradle:2.7.0 and sync the changes, you are given a message stating that is the fix as follows:
Configure project :app
Crashlytics could not find Google Services plugin task: processReleaseGoogleServices. Make sure com.google.gms.google-services is applied BEFORE com.google.firebase.crashlytics. If you are not using the Google Services plugin, you must explicitly declare `googleServicesResourceRoot` inputs for Crashlytics upload tasks.
Make sure
'com.google.gms.google-services'
is applied before:
'com.google.firebase.crashlytics'
Fixed the error for me.
I also didn't found anything, for now changing to firebase-crashlytics-gradle to 2.6.1 seems ok.
My project didn't use 'com.google.gms.google-services'. You need to add 'com.google.gms.google-services' to the app level Gradle file in the plugins and, its corresponding classpath dependency classpath 'com.google.gms:google-services:latest-version' in the project level Gradle file.
Also make sure com.google.gms.google-services comes before com.google.firebase.crashlytics as stated by other answers.
I already had the apply plugin lines in the correct order, yet I was still getting the build error and sync warning about the plugin task not being found. I considered the possibility of upgrading google-services, but version 4.1.0 was as high as I could make it. Any higher, and I would get errors about library dependencies not being found.
It turned out not only did I need to upgrade google-services to 4.3.14, defining the mavenCentral() repository in the project-level build.gradle wasn't enough; it also needed to be defined in the app-level build.gradle.
buildscript {
repositories {
google()
mavenCentral() // Add this line
}
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
Nowhere in the Get Started documentation did it mention needing to do this, so hopefully, this will help anyone who gets stuck in the same situation I was in.

Cannot specify -processorpath or --processor-path via `CompileOptions.compilerArgs`. Use the `CompileOptions.annotationProcessorPath` property instead

I'm cloning an android course project from GitHub, and facing a series of errors, I've manged to solve some of them till I stuck in last one, the scenario as follows:
1- error: Could not find com.android.support:appcompat-v7:25.1.0. (Solved).
2- error: File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it.(solved)
3-error: Cannot specify -processorpath or --processor-path via CompileOptions.compilerArgs. Use the CompileOptions.annotationProcessorPath property instead.
This one that I can't fixError snip
and after adding this implementation (
implementation 'com.google.firebase:firebase-core:17.4.3'), I get that error as well.
error: This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
Error snip
I've found that link that has exact fix to the errors mentioned in the question.
Cannot specify -processorpath or --processor-path via `CompileOptions.compilerArgs`
solution.
Delete “apply plugin: ‘android-apt’” line from your app module build.gradle file.
(Not necessary to work) Delete “classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.2’” from your top-level build.gradle file.
In “dependencies” section in build.gradle rename
apt ‘net.simonvt.schematic:schematic-compiler:0.6.3’
to
annotationProcessor ‘net.simonvt.schematic:schematic-compiler:0.6.3’
I’m using newest 26.0.2 buildToolsVersion as well as newest support libraries and everything works like a charm.
Remember to use newest gradle (4.1-all for now) and gradle plugin (3.0.0 for now). Add google repository to download newest support libraries. Sync and rebuild project. Now when you go to your manifest file, there should be no more red android:name=".provider.generated.SquawkProvider"
My top-level 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:3.0.0’
// Google Services plugin
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Let me know if it works.

How to invoke Annotation Processor from Gradle plugin

I am currently working on a Gradle custon plugin that should analyse my root project for specific configs in every subproject and then generate some kotlin source code in the build dir. I can't figure out a way to invoke my annotation processor from my gradle plugin which has a custom task for this matter.
Any ideas how to achieve this? Any resource/tutorial/documentation is also highly welcomed.
Thanks in advance and be safe.
After a long time of googling and mostly trying and failing, I finally figured out the solution to my question. Here is my task configuration.
Basically we have to provide the annotation processor's classpath as a project configuration. In my case I added this block to the project's build.gradle
allprojects {
configurations {
myProcessor //pick any name!!!
}
}
and then as a dependency in app build.gradle
dependencies {
myProcessor "PATH_TO_MY_PROCESSOR_JAR" //or maven dependency if it's uploaded to maven central
}
tasks.register(
"myTaskName",
JavaCompile::class.java
) {
compiler ->
with(compiler.options) {
isFork = true
isIncremental = true
}
with(compiler) {
group = shuttle.plugin.ShuttlePlugin.TASK_GROUP
destinationDir = outputDir
classpath = variant.getCompileClasspath(null)
options.annotationProcessorPath = configurations.getByName("myProcessor") //this is the missing piece!!
source = files(projectDir.resolve("src/main/java")).asFileTree
}
}
However, this task will only compile Java classes Only and not kotlin.
Any Idea how to fix this behaviour knowing that my plugin targets only android apps so I don't have direct access to kotlinCompile gradle default task?

Could not find com.google.firebase:firebase-crashlytics-gradle:17.0.0-beta01

I was trying to implement the new Firebase-Crashlytics SDK. After going through the document, I got the following error.
Could not find com.google.firebase:firebase-crashlytics-gradle:17.0.0-beta01.
I found the following.
Wrong : com.google.firebase:firebase-crashlytics-gradle:17.0.0-beta01.
Correct : 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta01'
To implement the new Firebase Crashlytics SDK you need to add firebase-crashlytics-gradle classpath and firebase-crashlytics dependency.
In your project-level build.gradle file, add the Crashlytics Gradle plugin:
buildscript {
repositories {
// Check that you have Google's Maven repository (if not, add it).
google()
}
dependencies {
// ...
// Check that you have the Google Services Gradle plugin v4.3.2 or later
// (if not, add it).
classpath 'com.google.gms:google-services:4.3.3'
// Add the Crashlytics Gradle plugin.
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta02'
}
}
allprojects {
repositories {
// Check that you have Google's Maven repository (if not, add it).
google()
}
}
In your app-level build.gradle file, apply the Crashlytics Gradle plugin:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services' // Google Services Gradle plugin
// Apply the Crashlytics Gradle plugin
apply plugin: 'com.google.firebase.crashlytics'
In your app-level build.gradle, add dependencies for Google Analytics and Crashlytics.
dependencies {
// Recommended: Add the Firebase SDK for Google Analytics.
implementation 'com.google.firebase:firebase-analytics:17.2.2'
// Add the Firebase SDK for Crashlytics.
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta01'
}
From here.
If you're migrating from Fabric, don't forget to update google-services.json (download it from your Firebase console). It could changed after migration. Migration is described here.
P.S. answer for future strugglers.
Updating these dependencies work for me
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
}

Resources