android studio gradle plugin problems out of the box - android

just installed android studio after getting a fresh install of win10. i created a new empety project and got this error:
Gradle sync failed: Plugin [id: 'com.android.application', version:
'7.2.1', apply: false] was not found in any of the following sources:
this is the code:
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.6.10' apply false
}
Edit: the sources were blank and the path to the file is C:\Users\RK33DV\AndroidStudioProjects\test\build.gradle

The problem is you're missing settings.gradle file. Try to add settings.gradle file to your project root directory with the following content:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "projectName"
include ':app'

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'

build.gradle: all buildscript {} blocks must appear before any plugins {} blocks in the script

My build.gradle file doesn't compile.
I have the following warning:
Build file 'C:\Users\User\AndroidStudioProjects**\build.gradle' line: 7
Could not compile build file 'C:\Users\User\AndroidStudioProjects**\build.gradle'.
startup failed:
build file 'C:\Users\User\AndroidStudioProjects**\build.gradle': 7: all buildscript {} blocks must appear before any plugins {} blocks in the script
This is my build.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
}
buildscript {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}

build.gradle dont look properly (i think)?

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

UnknownPluginException using Google Play Services and Plugins DSL

I'm creating a new application in Android Studio Bumblebee and this defaults to using the new Groovy DSL plugin management in settings.gradle.
I need to be able to use Google Play Services to enable Firebase functionality, however I am running into a build error when applying the com.google.gms.google-play-services plugin using the documentation here: Google Play Services Readme
I have added the following to my settings.gradle file:
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
plugins {
id 'com.android.application' version '7.1.0-alpha13'
id 'com.android.library' version '7.1.0-alpha13'
id 'org.jetbrains.kotlin.android' version '1.5.31'
id 'com.google.gms.google-services' version '4.3.10'
}
}
and the following to my app's build.gradle file:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
however when I build the application, I get the following UnknownPluginException:
Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
I have also tried the legacy method of classpath etc. but this results in a much longer error message regarding dependency resolution.
I'm not sure what I am doing wrong.
Adding the google-services plugin to the plugins {} block is causing errors. The alternate way that I've found is:
First, in your root build file (not the one in the app folder), inside the buildscript {} block, add this
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}
In the build file in the app folder, apply the plugin like this,
apply plugin: 'com.google.gms.google-services'
In step 1, using mavenCentral() is necessary as the google-services plugin downloads the linked dependencies like gson from maven central :)
By using Android Studio Bumblebee new Groovy DSL plugin management Add below line in build.gradle(Project:) plugins{} section and sync project will solve your problem.
id 'com.google.gms.google-services' version '4.3.10' apply false
your build.gradle(Project:) looks like
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
id 'com.google.dagger.hilt.android' version '2.41' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false
id 'com.google.firebase.crashlytics' version '2.8.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
your build.gradle(Module:) looks like
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id 'com.google.dagger.hilt.android'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
android {
compileSdk 32
signingConfigs {
config {
enableV3Signing true
enableV4Signing true
}
}
}
your settings.gradle(Project Settings) looks like
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyApp"
include ':app'

How to apply the com.android.application plugin using the new plugins DSL?

I have a project configured through the triple of:
Declare repository in top-level build.gradle:
buildscript { repositories { google() }}
allprojects { repositories { google() }}
Declare classpath dependency, so plugin artifact gets downloaded from the appropriate repository, in top-level build.gradle
buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' }}
Then, in the app build.gradle file, apply the plugin:
apply plugin: 'com.android.application'
I want to migrate this to use the new plugins DSL as enabled by the PluginsDependenciesSpec.
I then:
Declared the repository in settings.gradle:
pluginManagement { repositories { google() }}
Declared the plugin dependency in the app build.gradle:
plugins { id "com.android.application" version "3.1.3" }
But this fails to resolve:
FAILURE: Build failed with an exception.
Where: Build file '…/build.gradle' line: 2
What went wrong: Plugin [id: 'com.android.application', version: '3.1.3'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'com.android.library:com.android.library.gradle.plugin:3.1.3')
Searched in the following repositories:
Google
BintrayJCenter
maven(https://maven.fabric.io/public)
Gradle Central Plugin Repository
What am I missing to get Gradle to connect the dots here, so that it can connect the plugin.id to the appropriate JAR fetched from the appropriate repository?
Within the pluginManagement you can use resolutionStrategy and force usage of specific artifact from the google() repository.
pluginManagement {
repositories {
google()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id in ['com.android.application', 'com.android.library']) {
useModule("com.android.tools.build:gradle:${getProperty('version.plugin.android')}")
}
}
}
}
Then you can apply android plugins with using new plugins DSL:
plugins {
id 'com.android.application'
}
or
plugins {
id 'com.android.library'
}
Here is the documentation.

Categories

Resources