How to fix Gradle sync error in Android Studio 2.3? - gradle

How do I fix a Gradle sync error in Android Studio (latest version 2.3)?

This error occurs when the gradle version is not compatible. Please update your gradle version in project level build.gradle to 2.3.
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}

Related

Is there any way to create a new flutter project with upgraded gradle version?

I am using android studio for flutter project. Every time when I create flutter android studio says a new gradle version is available. So then I have to change it manually to new version. The problem is when I try to run app , it will download to new version. If I do not change it some plugins gives an error work with the old version.
This my build.gradle file.
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' //here I have to change it to 3.5.1
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}...
I tried to upgrade flutter,dart,android studio,gradle. But it does not work. If I create a new android project , it was created with new version. So how to create a new flutter project with upgraded gradle version?
You can't. The Gradle version is hard coded to flutter app's template (the same for the kotlin version). Typically a flutter version is also not guaranteed to be compatible with the latest gradle version, so maybe stick with the version from the template until you are sure it's compatible.
try gradle wrapper --gradle-version 7.2 on the terminal.

Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] was not found in any of the following sources

I have a fresh install of IntelliJ, I created a new kotlin gradle project using the following settings:
This produces the following build.gradle.kts, (the exact same file works on my Windows machine):
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.2.71"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Which produces this error, when trying to do a gradle refresh:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] 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 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.2.71')
Searched in the following repositories:
Gradle Central Plugin Repository
Check your Internet connection and make sure your Internet is not restricted.
I solved this problem by turning on proxy for all tunnels (not just HTTP) with a VPN app.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
// kotlin("jvm") version "1.2.71"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
}
//tasks.withType<KotlinCompile> {
// kotlinOptions.jvmTarget = "1.8"
//}
gradle sync by commenting the above lines. The gradle will be set up.
once the gradle is downloaded, uncomment those line and sync again.
if the dependencies are not downloaded properly, run 'gradle build' in the terminal and click on gradle sync.
This solved the issue for me.
(1) in my case (OpenJDK 11 on Ubuntu 18.04) the problem was Gradle not being able to download the POM file from gradle plugin-server. you can test it by entering this line into jshell:
new java.net.URL("https://plugins.gradle.org/m2/org/jetbrains/kotlin/jvm/org.jetbrains.kotlin.jvm.gradle.plugin/1.3.11/org.jetbrains.kotlin.jvm.gradle.plugin-1.3.11.pom").openStream()
(you can find your url by running gradle with --debug option)
So if you received an exception like this: InvalidAlgorithmParameterException: trustAnchors parameter must be non-empty then the trouble is CA-certs cache. which could be easily fixed by writing these lines into bash Ref:
sudo su
/usr/bin/printf '\xfe\xed\xfe\xed\x00\x00\x00\x02\x00\x00\x00\x00\xe2\x68\x6e\x45\xfb\x43\xdf\xa4\xd9\x92\xdd\x41\xce\xb6\xb2\x1c\x63\x30\xd7\x92' > /etc/ssl/certs/java/cacerts
/var/lib/dpkg/info/ca-certificates-java.postinst configure
By the way do not forget to restart gradle daemon before trying again. (gradle --stop)
(2) another reason could be your internet not having access to bintray.com (the internet of Iran or China) which you can test by putting this line on jshell :
new java.net.URL("https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.3.11/kotlin-gradle-plugin-api-1.3.11.pom").openStream()
If you received a connection timeout, it confirms this theory. In this case you need to buy and have proxy/vpn connected in order to be able to download these dependencies.
Check your gradle and kotlin (or Java) versions.
I got the same error and my issue is solved by specifying the kotlin version in build.gradle:
Before:
plugins {
id 'org.jetbrains.kotlin.jvm'
}
After:
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.4.10"
}
In my case (Ubuntu 20.04), problem was with gradle 7.2, installed from snap.
I have removed gradle 7.2, installed from snap and install gradle 7.2 from sdkman. Works fine for me.
If you are using java like me .I got the issue fixed by adding the following:
Root gradle
dependencies {
ext.kotlin_version = '1.4.10'
classpath "com.android.tools.build:gradle:7.0.4"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
......
}
App gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
dependencies {
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"
......
}
Ok, so the answer was very simple all along. For some reason I activated gradle's "Offline work" toggle and that was the cause of the problem.
To disable it simply go to Settings > Build, Execution, Deployment > Build Tools > Gradle and deselect the "Offline work" checkbox.
In my case the problem was because Charles Proxy. After closing Charles I could start working again
I updated my Kotlin version to 1.7.20 and fixed this problem.
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
I recently had similar issue with an empty project autogenerated by Intellij Idea.
Solved this problem by combining Java and Gradle versions.
Initially I had Oracle Java 8 with Gradle 6.8.3.
After several attempts I found a working combination - AdoptOpenJDK 11 and Gradle 5.6.4
In my case I changes the Gradle JVM in Settings > Build, Execution, Deployment > Build Tools > Gradle and it worked.
Disconnect from your VPN (or make sure you have an open internet connection), then restart Android Studio.
If you don't restart it sometimes it continues with invalid proxy properties.
This for Ktor devs. If you are working on a ktor application with the web project generator there is a chance the generator sets invalid jvm plugin version. So make sure you are setting correct version for jvm plugin. You can find the latest jvm plugin version here. Here is the sample build.gradle.kts file.
//Plugin section
plugins {
kotlin("jvm") version "1.8.0"
id("io.ktor.plugin") version "2.2.2"
}
//Dependancy section
dependencies {
...
testImplementation("io.ktor:ktor-server-tests-jvm:1.8.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.8.0")
...
}

Gradle version 3.3 does not support forTask() method on BuildActionExecuter

I just updated my Android Studio to 3.0 canary 1.
Now I am working on my existing project on Android Studio 3.0 canary 1.
By default gradle:3.0.0-alpha1 is set in my project: gradle_file.
So I changed my gradle version to 2.2.3 and now I'm getting this error:
Error:Failed to complete Gradle execution.
Cause: The version of Gradle you are using (3.3) does not support the
forTasks() method on BuildActionExecuter. Support for this is
available in Gradle 3.5 and all later versions.
I attached my gradle file here
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've just had the same issue. Fixed it by changing Gradle distributionUrl in "gradle-wrapper.properties".
Here is what I have configured:
#Wed Mar 22 16:13:58 BRT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
for more details
Offical video to help migaration
https://www.youtube.com/watch?v=oBsbI8ICYKg
see also comment below from #TmTron
Change in the file "gradle-wrapper.properties".
Put this line and Sync Project-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
This will work. For Check latest version services.gradle.org/distributions
After changed, Sync Project, Clean and Rebuild project once from Build menu.
This happened when trying to build debug apk.
SOLUTION: Update Gradle version to 3.5
Navigate to File -> Project Structure -> Project -> Gradle Version = 3.5
This works for Android Studio 3.0
Please follow the below steps:
Open your project in android studio
In Android menu, open gradle-wrapper.properties
Change the distribution url line with the below line
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
Thats it. Build your project now.
Screenshot is attached for more understanding.
I resolved the issue by changinf distributionUrl in the following code in gradle-wrapper.properties file
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Once add these with Top level Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
We have two way to deal with it.
You can update your gradle's version from the early one to 3.5 version product;
Or,you can figure your gradle wrapper to 4.1 version.
All of the ways are both useful.
Only Change the gradle URL to
"distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip"
as follow image :
Open gradle-wrapper.properties
Replace:
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
With:
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
Now sync project
Click here for more understand
put this code in gradle-wrapper.properties file and it will work with you
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Why am I getting "unsupported version of Gradle" with the tutorials app in Android Studio?

When I try to import the tutorials app to Android Studio, I get this message:
The project is using an unsupported version of Gradle.
Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
I’m new to Android Studio, and meter too. What’s the problem with Gradle?
I’m using Android Studio 1.0.1.
Android Studio 1.0.1 supports gradle 2.2.1+ and Android Gradle Plugin 1.0.0+
How to change the gradle version.
In your project you should have a folder gradle/wrapper.
Inside you will find the gradle-wrapper.properties file.
Change this line inside
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
How to change gradle plugin version:
In your project you should have a build.gradle file in the root folder.
Inside:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter() // or mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
Pay attention. Each module has a own build.gradle file. Inside you can override the default configuration.
More info here.
I too have faced this issue, To resolve this issue there are two things you need to try.
You need to remember exactly what version of gradle distribution url you were adding to your existing project.
if you didn't remember, you have to goto https://services.gradle.org/distributions/ and do trial and error. Add all versions to gradle distribution url like shown below.
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
only change the last version number 2.2.1-all to 3.5-all and so on.
In gradle-wrapper.properties, modify the gradle version. Change to a newer one. The reason is generally: gradle and JDK, different versions are not compatible. Change the JDK to the old version.

Android studio having fun of me with Gradle version

I have just updated Android Studio to 0.4.2, and the first time I launched it I got an error saying:
Failed to refresh Gradle project 'MyProject'
Gradle version 1.8 is required. Current version is 1.9. If using the gradle wrapper, try editing the distributionUrl in /home/alex/gradle/wrapper/gradle-wrapper.properties to gradle-1.8-all.zip.
Please fix the project's Gradle settings.
The fun fact no. 1 is that the specified path doesn't exist - anyway, I have changed the distributionUrl in gradle-wrapper.properties in my project to 1.8, and relaunching Studio now asks for 1.9!
Any ideas on how I can fix this?
SOLUTION
Solved this by deleting the gradle folder. It downloaded the libs and solved the dependencies on its own.
Android Studio version 0.4.2 wont work with Gradle 1.8 you have to use gradle 1.9
Check following things :
1.inside every build.gradle file in your project the gradle dependency should look like.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
2.If you are using Local Distribution change the path from File>Settings>Compiler>Gradle and point it to gradle 1.9.
Change the path in gradle-wrapper.properties to
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-bin.zip

Resources