Synchronize Gradle and Android Studio Versions - android

Android studio was taking up a massive amount of disk space on my computer (over 50 GB) and my old 90 GB ssd was completely full. I tried to reduce the amount of space that was being used by completely removing everything from android studio except my project and then reinstalling it.
There were some problems that I worked through, such as updating the sdk version, but I am stuck on this error message:
Error running app: This version of Android Studio is incompatible with the Gradle Plugin used. Try disabling Instant Run (or updating either the IDE or the Gradle plugin to the latest version)
I tried disabling instant run, but it did not fix the problem, and I like instant run anyway.
I also tried installing a new version of gradle and then pointing to it in settings/buildtools/gradle, and I've also tried checking the box to use the default wrapper instead.
I tried modifying my class path in build.gradle when I changed to gradle 3.0 in the settings above:
classpath 'com.android.tools.build:gradle:2.2.0-beta1'
My android studio is version 2.1.3/143.3101438
How do I get the right version of gradle installed and update my project to use it?

I got it working now. I had to specify the version of gradle in three places. First in settings/buildtools/gradle set it to use the default wrapper. Second specify the gradle version in build.gradle:
classpath 'com.android.tools.build:gradle:2.1.3'
Third, in gradle.wrapper.properties specify the gradle version:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
(I originally set it to ...gradle-2.13-all.zip, but it changed it to 2.14.1 after i put in 2.13, but it did not update the version in the build.gradle file)
I'm still very much confused what gradle is doing, why I need to specify the version 3 times, but at least it works.

Related

INSTALL_FAILED_INVALID_APK for debug only (release works)

I was running Android Studio 3.5. My code was compiling and installing onto the emulator just fine.
I updated Android Studio to 3.6.1.
The only parts of my code that change are:
gradle updated from 5.4.1 to 5.6.4
Android gradle build tools updated from 3.5.3 to 3.6.1
Now I get the following error when trying to run the debug flavor (release works fine) of my app
Installation did not succeed.
The application could not be installed:
INSTALL_FAILED_INVALID_APK The APKs are invalid.
I have tried to delete the emulator and make a new one. I have tried clean, rebuild, invalidate cache. Nothing seems to be working.
Found the solution to my own problem. Note to others, make sure your libraries and classpaths are always up to date. I had a classpath for firebase plugins that was not up to date. When applying the new gradle, this problem occurred. After updating the classpath everything installed smoothly again
This problem is usually caused due to a difference in the mainfest package name and the Gradle applicationId.
First, check that they both are same.
Then, check that there are no spaces in the package name and it has proper (.) separators.
Also, check that it has no other separators (- or,) other than (.).
This should work for you.
Do post your manifest and Gradle configuration file.

Android Studio update breaks Gradle again

So, like an idiot, I upgraded Android Studio.
And my project immediately stopped building because of gradle errors.
It says
12:06 Gradle sync started with single-variant sync
12:06 Gradle sync failed: Minimum supported Gradle version is 5.4.1. Current version is 5.1.1. If using the gradle wrapper, try editing the distributionUrl in /home/phil/Documents/PATH-TO-PROJECT/gradle/wrapper/gradle-wrapper.properties to gradle-5.4.1-all.zip (245 ms)
12:06 NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version=20.0.5594570
So I look in gradle-wrapper.properties and it does indeed say
#Wed Oct 30 11:57:04 BRT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
So the error message, if I'm interpreting it correctly says "change the gradle-wrapper.properties to refer to gradle-5.4.1" and, indeed, that's what the gradle-wrapper.properties DO refer to.
So I'm guessing this is an ambiguous error message or I'm just being stupid reading it.
Maybe although the error message is telling me to change TO 5.4.1, what it should really be telling me is either
a) upgrade my gradle to 5.4.1 because it's currently only 5.1.1.
If so, where do I do this? I never installed gradle myself. I just got it as part of the Android Studio bundle. So where in that Android Studio download can I do this?
or maybe
b) Android Studio automatically updated my gradle-wrapper.properties to 5.4.1, but really I need to change that properties file BACK to 5.1.1 because that's what I have installed.
How should I interpret and understand this problem?
I'm not really looking for a "magic spell" of "change these things" or "I cleaned my project and it worked for me".
I'm looking for a short but comprehensive explanation as to why these gradle incompatibility problems keep happening in Android Studio. So that I can understand what's actually going on and how to solve these things myself.
Update the Gradle version in gradle-wrapper.properties to5.4.1 and let it download that version. It doesn't matter what is globally installed, when using the wrapper (which fetches whatever is being requested). This is happening because the current build-tools plug-in (which has the same version as Android Studio) depends on Gradle >= 5.4.1. In directory ~/.gradle one often can remove old wrapper installations; keeping all projects at the same Grade version requires the least space on disk (since it keeps all Gradle versions ever built with, per user).
Alternatively, you could install Gradle >= 5.4.1 globally, eg. /opt/gradle/5.4.1 and remove the wrapper - but when being the only user on a computer, this is of no real advance, because manual updating is required.
I just updated Gradle and got a similar error.
In gradle-wrapper.properties, I changed
distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip
to
distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
tried to build, then changed it back again, and it built.

"Minimum supported Gradle version is 4.4" error started today; no code changes

Today, multiple developers on my team started seeing this error when they attempt to run any Gradle task.
* Where:
Build file 'C:\dev\src\my_app_name\app\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Minimum supported Gradle version is 4.4. Current version is 4.1. If using the gradle wrapper, try editing the distributionUrl in C:\dev\src\my_app_name\gradle\wrapper\gradle-wrapper.properties to gradle-4.4-all.zip
Absolutely no code or config changes were made; Gradle builds just suddenly started to fail. Anyone know why this would happen? My best guess is that a plugin with a dependency on a specific version of Gradle auto-updated itself, but I'm not sure how to figure out which one it is. The line number would suggest that it was the com.application.plugin plugin itself.
I am aware that Android Studio updates often require a corresponding upgrade to Gradle, but nobody on my team updated Android Studio. And, according to the Android-Studio-Gradle version compatibility table, Gradle 4.1 should still work fine with Android Studio 3.0.1, which is what I have been running for some time.
We recently started using Kotlin, and I thought that might be part of the problem, but completely removing everything related to Kotlin didn't help.
I have tried deleting the Gradle caches/ directory, running ./gradlew cleanBuildCache, deleting our project's build/ directories, killing Gradle daemons via ./gradlew --stop, and rebooting -- all to no avail.
I also tried upgrading to Gradle 4.4, but that resulted in a "CIRCULAR REFERENCE" NullPointerException error during DexMergerTransform (separate issue), for reasons that are entirely unclear to me. I'd like to be able to force my environment to NOT take on a Gradle 4.4 dependency right now... but I don't know what suddenly triggered this dependency.
The problem turned out to be that we were using a non-specific version of a plugin. When a change was made to the plugin, the new version was downloaded to our dev environments, and it introduced a dependency on a version of Gradle higher than the one we were using.
In our case, this was the culprit:
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
Downgrading to version 8.5.1 of the Butterknife plugin eliminated the dependency on Gradle 4.4.
You also have the option of linking to a specific pre-release "nightly" version. However, this is less than ideal, since these bits don't remain available for long, and you might want to download a build and keep it in your local lib. For example:
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-20180727.012508-40'
instead of down-grading, one could provide the plugin in version 9.0.0 with the expect version of Gradle, by editing the file gradle/wrapper/gradle-wrapper.properties; for example:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
version 4.5 works stable and might not create the circular reference, alike 4.4 does. and when looking at the issues tracker on GitHub, this Gradle plugin might add more problems, than it would serve any real purpose - because the Android SDK already supports two-way data-binding.
currently the artifacts still list 8.8.1 as the latest version; while a SNAPSHOT is barely stable... that nothing happend there since over a year, hints for that this project might have been abandoned... most likely because of Architecture Components data-binding.

Android Studio 2.0 Preview 8 issue with gradle 2.10 and plugin 2.0.0-alpha7

I had some issues with Gradle plugin 2.0.0-alpha6 and Gradle 2.10 and solved them by disabling Instant Run (as stated in Android Studio doesn't work fine with gradle 2.10 and gradle plugin 2.0.0-alpha5).
I then updated to gradle plugin 2.0.0-alpha7 without any issue
Today I updated Android Studio to the latest 2.0 Preview 8 version and I got the following error again:
Error:Could not find com.android.tools.build:gradle:2.0.0-alpha7.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.0.0-alpha7/gradle-2.0.0-alpha7.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.0.0-alpha7/gradle-2.0.0-alpha7.jar
Now, I see by clicking on those links that the two files don't exist... but, I get the same error if I revert to gradle plugin 2.0.0-alpha5 or 2.0.0-alpha6, do it doesn't make much sense. Is the maven environment down, maybe?
That's quite frustrating. Now, I tried to check whether Instant Run is enabled and I got a surprise: it's disabled and I cannot enable-disable it anymore, since Android Studio doesn't seem to understand I'm building using gradle.
Probably that's because it can't find the Gradle files, therefore doesn't let me enable/disable features that depend on te gradle plugin version. So, I don't know what to do.
I already incremented the max heap size in my build.gradle file
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
This is my full build.gradle file (except for some var settings I deleted from it): https://gist.github.com/MarKco/60f4ac63f7cafb783f3a
To enable Instant Run again (or at least not greyed out) you have to update to gradle plugin 2.0.0-alpha8. This might also solve your other problems.
from the release notes at http://tools.android.com/recent
We've just pushed Android Studio 2.0 Preview 8 to the canary channel,
as well as a new version of the Gradle plugin: 2.0.0-alpha8. You'll
want to update both; instant run in particular is only enabled when
using the latest versions of both:
Therefore try updating the gradle plugin to 2.0.0-alpha8

How do you find out what versions of gradle is used in Android Studio

In the build.gradle files, sometimes (I'm not sure when) you'll have to specify what version of gradle is used. The last few updates of Android Studio kept breaking some build files which listed the gradle version in use. I would have to update the gradle version number to fix the build file. I wanted to know if there's a way to figure out what version of gradle is included with Android Studio, instead of having to guess. I haven't been able to find out how to do this through Android Studio.
On Windows you can navigate to C:\Users\<user>\.gradle\wrapper\dists and you can see which gradle versions have been downloaded
If you're using gradle wrapper then you can change (or just check) gradle version number in gradle-wrapper.properties file. In order to do this you have to modify distributionUrl

Categories

Resources