build.gradle dont look properly (i think)? - android

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
this is only what i see in my build.gradle project. Im trying add this code (to get some custom toast cause the toast.view is deprecated):
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
but i cant see allprojects{} and the rest of things that should be there

There are different ways of defining repositories in Gradle. Recently, projects created in the Android Studio wizard no longer include an allProjects block in build.gradle. They configure the dependency repositories in a dependencyResolutionManagement block in the settings.gradle file. For example:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}

Related

Trying to add Graph in Android Studio but keep getting this error

It says that, Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
buildscript{
dependencies{
classpath 'com.google.gms:google-services:4.3.15'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
allprojects{
repositories {
maven { url 'https://jitpack.io' }
}
}
and I already put this on my dependencies
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

Changes in Android Studio's project gradle file

I have recently updated my Android Studio to latest version. But the gradle file here seems bit different.
here is the gradle code :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
I want to add these below jitsi lines in the project gradle file. how should I paste it so that it syncs properly without any errors.
here is the jitsi code :
allprojects {
repositories {
maven {
url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
}
google()
mavenCentral()
maven { url 'https://www.jitpack.io' }
}
}
I have tried changing the gradle file by adding or replacing the above lines, Nothing changes. It is throwing an error.
As you appear to be using the recently revised build configuration scripts, you should be able to declare your repositories under the settings.gradle file:
pluginManagement {
// Plugin repositories go here
}
// ...
dependencyResolutionManagement {
/**
* The dependencyResolutionManagement {repositories {...}}
* block is where you configure the repositories and dependencies used by
* all modules in your project, such as libraries that you are using to
* create your application. However, you should configure module-specific
* dependencies in each module-level build.gradle file. For new projects,
* Android Studio includes Google's Maven repository and the Maven Central
* Repository by default, but it does not configure any dependencies (unless
* you select a template that requires some).
*/
// The following line makes it so that project modules (such as your
// "app" module) can't declare their own repositories {} block
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// Add your repositories here...
maven {
url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
}
maven { url 'https://www.jitpack.io' }
}
}
only buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
As for this error, this is because plugins blocks are always resolved first, and so any other code must be declared after that block:
// There shouldn't be any code before this!
plugins {
}
// Okay to have build script code here...
Android studio latest version you move the jitsi repository in the project's settings.gradle file
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
mavenLocal()
}
}

where can I add - allprojects repositories in gradle.build file android

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
I want to add a new dependency in gradle.build file but don't know where to add this section
There are usually two build.gradle files - one in the root folder of your project, and one in the app module (also any other modules you might have). You should add the above snippet within the root build.gradle file, for example:
// 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
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Apply Firebase to Android Studio Project version Bumblebee

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

import lottie to gradle

I want to add lottie dependency in my project.
this is the way that lottie document recommends
implementation "com.airbnb.android:lottie-compose:$lottieVersion"
allprojects {
repositories {
...
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}}
here is my gradle
buildscript {
ext {
compose_version = '1.1.1'
lottie_version = '0.5.4-SNAPSHOT'
}}
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false}
task clean(type: Delete) {
delete rootProject.buildDir}
as you can see there is no allProjects in my gradle.
how can I add Maven repository?
Go to your build.gradle module and inside dependencies section add
implementation "com.airbnb.android:lottie-compose:$lottieVersion"
Now go in settings.gradle and inside dependencyResolutionManagement -> repositories add this
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

Categories

Resources