I've been trying to build my android app with gradle build, and to get it download required dependencies and jar files automatically, I added in my settings.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
And my build.gradle looks like this
plugins {
// Apply the application plugin to add support for building a CLI application in Java
}
repositories {
google()
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
implementation 'com.google.guava:guava:30.1.1-jre'
classpath 'com.android.tools.build:gradle:7.1'
}
application {
mainClass = 'MyProject.App'
}
tasks.named('test') {
useJUnitPlatform()
}
When I try running gradle build, I get an error:
A problem occurred while evaluating settings 'MyProject'.
> Plugin with id 'com.android.application' not found.
I did some research, and every answer on the Internets says it's probably due to the plugin version, so I tried solving the problem by using versions 4.1, 4.2, 7.1, and 7.0 for of 'com.android.tools.build:gradle', with no avail.
CodePudding user response:
Updated April 2, 2022
You need to update to the latest gradle version to solve this issue.
Please make sure you are on the latest Android Studio
and then update your project level build.gradle by updating this dependency
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
It might show a popup asking your permission to update gradle, please update and it will download the latest distribution automatically and the issue will be resolved.
Or else you can download gradle manually:
Open YourProject > gradle > wrapper > gradle-wrapper.properties and replace
distributionUrl=https\://services.gradle.org/distributions/gradle-version-number-all.zip
With
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Rebuild the project or just run gradle sync again.
CodePudding user response:
You are adding plugins in wrong place.
plugins are added inside build.gradle(app) and classpaths are added inside build.gradle(project).
for example, inside build.gradle(app)
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies { }
}
inside build.gradle(Project)
dependencies{
classpath 'com.android.tools.build:gradle:7.1'
}
CodePudding user response:
save a copy of your app
in your settings.gradle
rootProject.name = 'MyProject'
in your build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
google()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
change your gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-
bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Invalidate cache
and let your project rebuild