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

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.

Related

react-native and firebase native: Could not find method plugins

I am trying to configure a project that uses react-native and google firebase native.
The set up for react-native worked fine, but I ran into a problem with google firebase native.
I followed the instructions at rnfirebase.io.
When I try to sync My project with gradle files from Android Studio, I get the following error:
Build file 'C:\github\flashcards\flashcards\android\app\build.gradle' line: 139
A problem occurred evaluating project ':app'.
> Could not find method plugins() for arguments [build_2psolmxgn6smlx7165ef739cv$_run_closure1$_closure5#1b639892] on extension 'android' of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
...
Here is the relevant portion of my /android/build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
...
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath('com.google.gms:google-services:4.3.14')
}
}
allprojects {
repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup "com.facebook.react"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}
I added the following two lines to the top of my /android/app/build.gradle file:
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
Any suggesions for how to fix this problem?
I expected the Sync Project with Gradle files command to complete successfully, but I receive the error described above.

Project level build.gradle not containing the appropriate code

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'
}

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.

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