Android Build issue while creating a new project - android

I have been struggling with this gradle for the last one week. None of the earlier questions on gradle issue could solve my problem.
Things I did :
Download the latest gradle. I did it by changing the path at distribution URL in gradle-wrappper properties.
(It will download the latest one say 2.14. but, When I create a new project, It will be set to 2.10 and then back to same dirt)
Should I download the gradle for every project I create ? ... Help me fix this.
Thanks in advance :)
This is the error when I create a new project

Use the latest version of gradle with in build.gradle.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}

Don't confuse gradle and the android plugin for gradle.
1) You can define the gradle distribution used by a project in the file
gradle/wrapper/gradle-wrapper.properties
For example:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.14-all.zip
Each project can use a different version. You will find the distributions file inside \user\.gradle\wrapper\dists folder.
2) Gradle is a build tool, but it requires specific plugin to work.
Android Tool Team is releasing the Android plugin for Gradle.
You can define the plugin inside the build.gradle file in the project.
For example:
classpath 'com.android.tools.build:gradle:2.1.3'
Each project (or module) can use a different version.
Also go to File > Settings > Builds,Execution,Deployment > Build Tools > Gradle
and set Use default gradle wrapper

Related

Android studio gradle upgrade

Anyone has an idea on how to upgrade gradle from within android studio. The pop-up appears telling me to upgrade gradle but version never updates.
I've tried downloading it and unzipping it in the .gralde folder and changing the path, a gradle error persists and resolving it only re-creates the old gradle file and overwrites the new one.
Set gradle and android plugin version under the Projects tab in Project structure (File -> Project Structure). Clicking Ok will sync gradle files.
Alternatively to update gradle through code this may be helpful.
Update Gradle version
find gradle folder inside your project
Open gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Update Android Gradle plugin
Open build.gradle file of your project
Inside buildscript tag update
classpath 'com.android.tools.build:gradle:2.3.3'
After making these changes refresh gradle dependency.

Could not find gradle 3.1

The latest version of gradle is 3.1 enter link description here
but Android Studio is only using 2.2?
enter link description here
This seems likes a huge discrepancy. My configuration:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2'
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:3.2'
classpath 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
}
}
allprojects {
repositories {
jcenter()
}
}
When I try to find gradle 3.1, I get an error that it cannot find it. Same now with 2.2 > Could not find com.android.tools.build:gradle:2.2.
But gradle -v shows
gradle -v
------------------------------------------------------------
Gradle 2.2
how do I resolve this?
You are confusing Gradle with the Android gradle plugin, which generally matches the version of Android Studio. The latest version (at time of writing) is 2.2.2. It is generally set in your project's base build.gradle as you have shown above.
The Gradle wrapper is what you're looking for. You can change the wrapper's settings in your project's gradle/wrapper/gradle-wrapper.properties file.
Change
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
Again, this is separate from the Android gradle plugin, which simply marries Gradle with Android Studio.
Find all distributions here
Here is the Gradle Version Compatibility for Android Studio
Gradle
refer to link
A problem occurred research project ': sample'.
Failed to apply plugin [id 'com.android.application']
Minimum supported Gradle version is 3.3. Current version is 3.2.1.
The current gradle configuration is also changed to 3.3. The project is running without problems, but can not use the command line (gradle and ./gradlew).
Refer to the online program:
1. Modify gradle-wrapper.properties, and Invalidate Caches / Restart ..., or do not work.
Later in the gradle forum to find a program: Thank you Henry
As new release with the fix not available yet, the former walk-around works fine.
Buildscript {
System.properties ['com.android.build.gradle.overrideVersionCheck'] = 'true'
...
}
. So mark what.
Correction statement : I later found that I installed the sdkman tool,
the tool installed 3.2.1 version, and this should be related (⊙ o ⊙)!
. At the beginning of the show gradle version, will show 3.2.1
version (I am still very depressed, change or show 3.2.1), I have
changed to the environment variable 3.3. I set the gradle environment
variable first, the following is set sdkman environment variable (this
order may also affect). So the final reason is still installed 3.2.1
version.

Android Studio: Re-download dependencies and sync project

I downloaded an open source game "ChaseWhisplyProject" source code from Github.
I imported the project in my Android Studio (Version 1.5.1).
It shows following error message:
Error:Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Re-download dependencies and sync project (requires network)
I changed all the dependency versions to latest one bu still it is showing the same message.
It has two modules under the main project 1) BaseGameUtils & 2)ChaseWhisply.
The above modules are not shown in bold letters (I think it should be shown in bold letters like module "app").
Following are the gradle files.
1) Root Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
repositories {
jcenter()
}
}
2) BaseGameUtils Module Gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
3) ChaseWhisply Module Gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile project(':BaseGameUtils')
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
lintOptions {
// TODO fix and remove !
disable 'MissingTranslation', 'DuplicateIds', 'ExtraTranslation'
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 22
versionName "0.3.6"
}
}
4) Settings.gradle
include ':ChaseWhisply', ':BaseGameUtils'
What is wrong over here? Please help.
While importing a libGDX project I got the same message from Android Studio 2.2.
Went to File->Project Structure then selected Project and set
Gradle version
and
Android Plugin Version
to values identical to another project I had recently created with Android Studio 2.2 and updated SDK. Could then sync gradle. Did Build->Build Clean with no issues. Then did Run->Clean and Rerun and project ran fine.
Hope this helps.
It basically means that the gradle zip file in the cache folder is corrupted, if you don't want to change the version like the up-voted answer then you must delete the folder for your gradle version you're using for this project from the below path.
Then just retry the sync and android studio will download it again
C:\Users\ [user here] \.gradle\wrapper\dists
ex: if you're using 3.3 for this project you'd be deleting the folder
C:\Users\[user here]\.gradle\wrapper\dists\gradle-3.3-all
I was also facing the same issue. The solution worked for me was go to "gradle\wrapper\dists" and deleted the folder "grade-4.10.1-all" folder and downloaded the same version after that i pasted the extracted folder in same address.After that I again synchronized the android studio. I worked for me.
I face the same problem and I search for it and found a best solution and i works for me:
Manually download Gradle 3.3 binary (direct link: https://services.gradle.org/distributions/gradle-3.3-bin.zip)
Open your android studio root directory, and extract the zip to the gradle folder (for example: program files/android-studio/gradle/gradle-3.3)
Open Android Studio, go to File->Settings-> (Build, Exectution, Deployment) >Gradle and set "Gradle home" to point your new gradle-3.3 folder.
Apply and sync.
May be incompatible with Gradle and maven version
delete project dir/gradle/wrapper
put a right version gradle into it
run again
change the gradle-wraper-properties distributionUrl to your local downloaded gradle such as
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
I solved this issue by this following steps
1.C:\Users\System name.gradle\wrapper\
2.Inside wrapper folder u will find grale file with some version, You just have to delete it
3.Come/Go to android studio and Go to File->Sync project with Gradle Files.
4.Android studio automatically download the require gradle file.
5.And now go for coding
The close android studio then goes to the directory and you will find this type of folder. I saw in my pc. after deleted then clean project and sync. its works fine.
you just delete from this directory
C:\Users\ [user here] .gradle\wrapper\dists
if you use 3.3 version in android studio. you can see like this
C:\Users[user here].gradle\wrapper\dists\gradle-3.3-all
Well, It's a bit late, but usually happens when something went wrong in Android Studio's initial launch (eg. system crash, connection loss or whatever). We can call it bad programming or lazy QA.
To fix this close Android Studio and delete everything from the following directory. Don't worry files will be downloaded on next launch.
For Windows: C:\Users\your-username.gradle\wrapper\dists
For Linux: ~/.gradle/wrapper/dists
For mac: ~/.gradle/wrapper/dists
You can also Gradle manually to fix this issue, But it's better to let Android studio does this work. .
Clean Project is a way to go. After you clean project, make sure you rebuild it. Usually it solves the gradle issues for me.
In my case I was running IntelliJ IDEA as non root user.
If you want to use the new features, you should not revert it to the old version, just delete the directory ~/.gradle recursively, then restart Android Studio.
Update your gradle version and update with required version of gradle and syn your project.
https://services.gradle.org/
First of all, open your gradle-wrapper.properties file from the project then note down the version of the Gradle.
It could be like this:
distributional=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
So, here my Gradle version is 6.5. It could be different in your case.
After this, open file explorer and open your project folder. There you will be having the Gradle folder open it, inside it the version will be mentioned of your previous Gradle.
Now you will have to download the Gradle file according to the wrapper.properties(for example nothing but 6.5 version).
You can download it from here
Extract it
paste it to the Gradle folder
open your project > file > settings > Build, Execution, Deployment > Gradle, then select the newly downloaded Gradle file in the Gradle user home.
Then run your project.
This worked for me - go to https://gradle.org/releases/ and download latest stable version (binary-only works fine). extract and insert into C:\Users\OWNER\.gradle\wrapper\dists folder.
Open Android Studio settings > Build, Execution, Deployment > Gradle, use gradle from: specific location.
The following steps solved my problem :
1.C:\Users\System name.gradle\wrapper\
2.Inside wrapper folder u will find grale file with some version, You just have to delete it
3.Come/Go to android studio and Go to File->Sync project with Gradle Files.
4.Android studio automatically download the require gradle file.
5.And now go for coding

Fix Plugin Version and Sync Project

I have recently updated my Android Studio.
After updating it, When I am trying to import or open a project it gives me following error :
Gradle Sync Issue
Error:Error:Gradle 2.4 requires Android Gradle plugin 1.2.0 (or newer) but project is using version 1.1.0.
Please use Android Gradle plugin 1.2.0 or newer.
Fix plugin version and sync project
Is there any solution for this problem ?
In your build.gradle you should use a newer version of the gradle plugin.
Use classpath 'com.android.tools.build:gradle:1.3.1'instead of classpath 'com.android.tools.build:gradle:1.1.0'. Or at least 1.2.0, as the error points out.
change in your progect build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
As Android Studio was just officially updated to 1.3 (Gradle as well).
Please Change gradle version to 1.3.+ in build.gradle . It should now look like this:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.+'
// in the individual module build.gradle files
}
I met this question,too. Modifying dependencies stuff is confuse me. From#Mykaelos answer, For Windows Android Studio, Go into File > Settings > "Build, Execution, Deployment" > "Build Tools" > Gradle and change it to "Use default gradle wrapper (recommended)", I tried it in early hours, and it works for me.

Updating Android Studio to version 0.4.0. nothing works! Which fixes?

I've made some waste code. After some mistakes I checkout latest commit. I expected to restart with any without any hitch. But building project now I receive the message:
Waiting for device.
Target device: samsung-gt_i8190n-47900693715f5036
Uploading file
local path: /Path/to/file.apk
remote path: /path/to/file/com.example
Local path doesn't exist.
(* I've removed complete local and remote path in this post ...)
Thus, when I try to sync project with gradle files, a new message from editor arrives:
Failed to refresh Gradle project 'NutriMondoProject'
Project is using an old version of the Android Gradle plug-in.
The minimum supported version is 0.7.0.
Please update the version of the dependency 'com.android.tools.build:gradle'
in your build.gradle files.
Search in build.gradle files
I feel like a fish out of water.
You have updated to Android Studio 0.4.0
it requires gradle plugin 0.7.+ and gradle-wrapper 1.9.
Change your build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
Then change your gradle-wrapper.properties:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip
Then sync your project with gradle files.
Launch gradlew clean to clean your build.
It's because you updated your Android Studio to version 0.4.0.
Follow those steps to make it work :
http://tools.android.com/recent/androidstudio040released

Categories

Resources