i'm studying how to use tensorflow lite on android studio with kotlin, and i got a problem now. i was referring a project to study, and this author's gradle file is very different with what i have been knowing.
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--> this is what i have been knowing from the first time.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--> and this is the gradle file for project that i'm reffering.
what i'm wondering aboout is why the author is not using plugins{} and having buildscript{} and allprojects{}. plus even though i copied and pasted it on the new project that i made, it does not work and throws the error.
error message img
what should i do for this?
Related
I just updated Android Studio and started a new project. But now the project grade file seems different.
Here are the lines:
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now, for example, I need to paste the Firebase lines in the project level Gradle file. Where should I do it?
Here's the Firebase code:
buildscript {
repositories {
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google() // Google's Maven repository
}
}
In all of my previous projects, the Gradle structure was also like that. Now I'm a little confused about what to do.
But now the project grade file seems different.
Yes, starting with the new Bumblebee update of Android Studio, the build.gradle (Project) file is changed. In order to be able to use Google Services, you have to add to your build.gradle (Project) file the following lines:
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false 👈
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And inside your build.gradle (Module) file, the following plugin IDs:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services' 👈
}
In this way, your Firebase services will finally work.
P.S. Not 100% sure if the Firebase Assistant is updated with these new Android Studio changes.
Edit 2022-14-07:
Here is a repo that uses this new structure:
https://github.com/alexmamo/FirestoreCleanArchitectureApp
Edit:
There is nothing changed regarding the way you add dependencies in the build.gradle (Module) file. If for example, you want to add Firestore and Glide, please use:
dependencies {
//Regular dependecies
implementation platform("com.google.firebase:firebase-bom:29.0.4")
implementation "com.google.firebase:firebase-firestore"
implementation "com.github.bumptech.glide:glide:4.12.0"
}
Edit2:
With the new updates, you don't need to worry about adding any lines under the repositories { }. That was a requirement in the previous versions.
I've had the same problem just add in the gradle.build project
id 'com.google.gms.google-services' version '4.3.0' apply false
and then add in gradle.build module
dependencies {
//Regular dependecies
implementation platform("com.google.firebase:firebase-bom:30.4.0")
implementation "com.google.firebase:firebase-firestore"
}
You will find your classpath from https://console.firebase.google.com/
You will find something like this in the firebase(if you already got your classpath then you can ignore this section)
buildscript {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
...
// Add the dependency for the Google services Gradle plugin
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
...
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}
just copy the classpath
1)In build.gradle(project)
before plugins make these changes-->
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.13'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2)In build.gradle(module) add these lines in pulgins and dependencies section
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics'
}
I just updated Android Studio and started a new project. But now the project grade file seems different.
Here are the lines:
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now, for example, I need to paste the Firebase lines in the project level Gradle file. Where should I do it?
Here's the Firebase code:
buildscript {
repositories {
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google() // Google's Maven repository
}
}
In all of my previous projects, the Gradle structure was also like that. Now I'm a little confused about what to do.
But now the project grade file seems different.
Yes, starting with the new Bumblebee update of Android Studio, the build.gradle (Project) file is changed. In order to be able to use Google Services, you have to add to your build.gradle (Project) file the following lines:
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false 👈
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And inside your build.gradle (Module) file, the following plugin IDs:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services' 👈
}
In this way, your Firebase services will finally work.
P.S. Not 100% sure if the Firebase Assistant is updated with these new Android Studio changes.
Edit 2022-14-07:
Here is a repo that uses this new structure:
https://github.com/alexmamo/FirestoreCleanArchitectureApp
Edit:
There is nothing changed regarding the way you add dependencies in the build.gradle (Module) file. If for example, you want to add Firestore and Glide, please use:
dependencies {
//Regular dependecies
implementation platform("com.google.firebase:firebase-bom:29.0.4")
implementation "com.google.firebase:firebase-firestore"
implementation "com.github.bumptech.glide:glide:4.12.0"
}
Edit2:
With the new updates, you don't need to worry about adding any lines under the repositories { }. That was a requirement in the previous versions.
I've had the same problem just add in the gradle.build project
id 'com.google.gms.google-services' version '4.3.0' apply false
and then add in gradle.build module
dependencies {
//Regular dependecies
implementation platform("com.google.firebase:firebase-bom:30.4.0")
implementation "com.google.firebase:firebase-firestore"
}
You will find your classpath from https://console.firebase.google.com/
You will find something like this in the firebase(if you already got your classpath then you can ignore this section)
buildscript {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
...
// Add the dependency for the Google services Gradle plugin
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
...
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}
just copy the classpath
1)In build.gradle(project)
before plugins make these changes-->
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.13'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2)In build.gradle(module) add these lines in pulgins and dependencies section
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics'
}
I'm trying to add Firebase SDK, follow the step guide of Firebase:
enter image description here
but the new version of Android Studio has a different build.gradle file, just:
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And I don't know how right to add code to my file. I've tried this:
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'
}
}
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
allprojects {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
}
But the log here is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'Uber clone'
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle
at build_8l5l0a77l47futp20icywdlc2$_run_closure2$_closure3.doCall(D:\Android\AndroidProjects\Uberclone\build.gradle:25)
at build_8l5l0a77l47futp20icywdlc2$_run_closure2.doCall(D:\Android\AndroidProjects\Uberclone\build.gradle:23)
at build_8l5l0a77l47futp20icywdlc2.run(D:\Android\AndroidProjects\Uberclone\build.gradle:22)
There is no need to add the repositories and the allprojects inside the Gradle file. This is because both are already present inside the setting.gradle file. To solve this simply remove them as you can see below:
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:4.3.10'
}
}
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I resolved this issue by commenting out 'dependencyResolutionManagement' section which is present in the settings.gradle.
Go to Gradle Scripts -> settings.gradle -> comment out 'dependencyResolutionManagement'
//dependencyResolutionManagement {
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
// repositories {
// google()
// mavenCentral()
// }
//}
Then paste the all project repository in Gradle Scripts -> build.gradle -> paste it below 'plugins' section
like this-
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
allprojects {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}
I've checked this answer:
https://stackoverflow.com/a/34834772/13519865
It tells us to remove this line
apply plugin: 'com.google.gms.google-services'
Removing the line as asked completes the build, but I can't use Firebase (ofc!), it caused a new error, which tells me to add the line:
https://stackoverflow.com/a/40085096/13519865
So, I'm stuck in a loop here.
Related code sample added here https://github.com/Cyberavater/A.Reader
This issue started after updating the com.android.tools.build:gradle to version 7.3.0 and was fixed for me after updating the com.google.gms:google-services to version 4.3.14.
Edit: 2023-01-04
I have seen the same issue with the latest Android Studio Dolphin release, where you need to specify the Gradle version to be 7.3.1 and Google Services 4.3.14.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
dependencies {
classpath 'classpath "com.google.gms:google-services:4.3.14'
}
According to the new Chipmunk update of Android Studio, if you need to use Google Services, you have to add the following lines of code inside your build.gradle (Project) file:
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'com.google.gms.google-services' version '4.3.14' apply false 👈
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And inside your build.gradle (Module) file, the following plugin IDs:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services' 👈
}
change this line in >> android/build.gradle
classpath 'com.google.gms:google-services:4.3.10'
to
classpath 'com.google.gms:google-services:4.3.14'
Read this if Alex Mamo's answer does not solve the problem for you.
The new updates of Android Studio prioritize or prefer the settings.gradle file above build.gradle(project) for plugin management. There are two possible solutions.
Solution 1. Update your existing project as follows.
Update your settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
gradlePluginPortal()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven {
url "https://plugins.gradle.org/m2/"}
}
}
rootProject.name = "Your App Name"
include ':app'
Update your build.gradle(project). Use your Gradle version, this example uses version 7.3.0, and google-services: 4.3.14.
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url "https://plugins.gradle.org/m2/"
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.14.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'com.google.gms.google-services' version '4.3.14' apply false
// other plugins in build.gradle(project)
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Add this to your build.gradle(app)
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
// other plugins
}
Solution 2. You can create a new project and move all your classes and XML into the new project.
I was facing the same issues but after updating the dependency the issues were resolved.
in my project level Gradle file previous it was as below:
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.google.firebase:perf-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
after updating as below, It was working fine with me.
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath 'com.google.firebase:perf-plugin:1.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Try with deleting .idea and .gradle folders from root of your app , an then from main app module ... If this doesn't work , then you must clone your project, making new one with same package name ... This is bug in Android Studio Dolphin , and I solved it with cloning with new project with same package name
First check your build.gradle(project) and paste these code below the plugins and also sync your project.
task clean(type: Delete) {
delete rootProject.buildDir 😊
}
I just updated Android Studio and started a new project. But now the project grade file seems different.
Here are the lines:
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now, for example, I need to paste the Firebase lines in the project level Gradle file. Where should I do it?
Here's the Firebase code:
buildscript {
repositories {
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google() // Google's Maven repository
}
}
In all of my previous projects, the Gradle structure was also like that. Now I'm a little confused about what to do.
But now the project grade file seems different.
Yes, starting with the new Bumblebee update of Android Studio, the build.gradle (Project) file is changed. In order to be able to use Google Services, you have to add to your build.gradle (Project) file the following lines:
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false 👈
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And inside your build.gradle (Module) file, the following plugin IDs:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services' 👈
}
In this way, your Firebase services will finally work.
P.S. Not 100% sure if the Firebase Assistant is updated with these new Android Studio changes.
Edit 2022-14-07:
Here is a repo that uses this new structure:
https://github.com/alexmamo/FirestoreCleanArchitectureApp
Edit:
There is nothing changed regarding the way you add dependencies in the build.gradle (Module) file. If for example, you want to add Firestore and Glide, please use:
dependencies {
//Regular dependecies
implementation platform("com.google.firebase:firebase-bom:29.0.4")
implementation "com.google.firebase:firebase-firestore"
implementation "com.github.bumptech.glide:glide:4.12.0"
}
Edit2:
With the new updates, you don't need to worry about adding any lines under the repositories { }. That was a requirement in the previous versions.
I've had the same problem just add in the gradle.build project
id 'com.google.gms.google-services' version '4.3.0' apply false
and then add in gradle.build module
dependencies {
//Regular dependecies
implementation platform("com.google.firebase:firebase-bom:30.4.0")
implementation "com.google.firebase:firebase-firestore"
}
You will find your classpath from https://console.firebase.google.com/
You will find something like this in the firebase(if you already got your classpath then you can ignore this section)
buildscript {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
...
// Add the dependency for the Google services Gradle plugin
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
...
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}
just copy the classpath
1)In build.gradle(project)
before plugins make these changes-->
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.13'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2)In build.gradle(module) add these lines in pulgins and dependencies section
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics'
}