Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Android Studio Arctic Fox Canary 8, the app level build.gradle does not generate `allprojects` section and causes error when manually added

When creating a new project in Android Studio Arctic Fox Canary 8, this is the app level build.gradle

// 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.0.0-alpha08"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

When creating the same new project in the Android Studio 4.1.2, the app-level build.gradle file is this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

One of the libraries I am using requires the allprojects

I manually tried to add the allprojects section in Canary 8, received this error:

 problem occurred evaluating root project 'My Application'.
> Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

Why was the allprojects in Android Studio Canary 8 was removed and how can I add it back so that I can use the libraries?

like image 884
dsf Avatar asked Mar 04 '21 13:03

dsf


People also ask

How do I fix build gradle?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.

What is app level build gradle file?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.

How to add repositories to Gradle project?

So, in settings.gradle you can add the repositories you want to download and add to the project

Why it collides with Gradle plugin?

Before this release we used build.gradle (Project level) file to define repositories. Now you should write then into settings.gradle file. That's why It collides with Gradle plugin and generate this error message:

How to fix Google Gradle project label changes?

Google has made some changes in the project label Gradle. you can fix this by removing all project label configuration to setting.gradle file. Remove this code in the Gradle file and all your plugins code in setting.gradle file. Like below.

Is there an allprojects closure in Android Studio?

Prior to Android Studio Arctic Fox, the Studio new-project wizard would create a project-level build.gradle file that contained an allprojects closure: allprojects { repositories { google () mavenCentral () jcenter () // Warning: this repository is going to shut down soon } } Arctic Fox and higher do not include this.


Video Answer


3 Answers

In settings.gradle you can add the repositories you want to add to the project

dependencyResolutionManagement {
   repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
   repositories {
      google()
      mavenCentral()
      jcenter()
      maven { url "https://maven.xyz.com" }
    }
}
like image 58
S Haque Avatar answered Oct 20 '22 15:10

S Haque


In settings.gradle just comment out the whole block

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}
like image 28
shasia858 Avatar answered Oct 20 '22 13:10

shasia858


Go to setting.gradle and replace the line:

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

with:

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

That's a gradle setting which allows this to work.

like image 41
Abdullah Fahad Avatar answered Oct 20 '22 13:10

Abdullah Fahad