How to find to the latest gradle version and the wrapper - android

Hi I'm fairly new to android development. I have a question regarding the Gradle version and the distribution url in gradle-wrapper.properties
classpath "com.android.tools.build:gradle:$gradle_version"
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
So every once a while I need to update gradle version (because android studio requires it). How do I find the new version number. Sometimes I need to update the gradle wrapper too, so how do I find the new distributionUrl that works with new gradle version?
It feels no one talk about this part of the android development and there isn't good documentations especially after google io

The Gradle Wrapper version can be changed by executing ./gradlew wrapper --gradle-version=4.9 as described here. This will automatically update the distributionUrl in gradle-wrapper.properties. If you want to manually set the distributionUrl, you can rely on the URL conforming to the same pattern as in your example. In other words, you can simply change the part of the URL that specifies the version (4.4 in your example) to the desired version. Check the repository, you will see that all releases are available at URLs that conform to the pattern https://services.gradle.org/distributions/gradle-X.Y-DISTRIBUTIONTYPE.zip (with capitalization indicating variable parts). The list of releases are also available in more reader-friendly format on the "Releases" page of the Gradle Website.

Related

How to know if there's a dependency update using Gradle Version Catalog

My project is using now Version Catalog for all the Gradle modules, and now using the type safe declaration of dependencies in the build.gradle file I don't get any suggestions from the IDE when there's an update of a specific dependency.
What would be the best approach to know if there's an update of a dependency, instead of checking manually one by one?
My recommendation is to use the gradle-versions-plugin or this extension of it (https://plugins.gradle.org/plugin/se.ascp.gradle.gradle-versions-filter). Both add an additional gradle task dependencyUpdates to your project that will tell you which version updates are available.
Also works fine in combination with the new versions catalog feature you mentioned. I am using it too.

How to have gradle download a server specified version of a dependency at build time

Say I create a library and I added it as a dependency to my project gradle files.
I would like to know how and if it is possible to specify the version number on a/my server and have Gradle check the version number at build time & update the library if necessary without me having the explicitly update the version number in my gradle files.
So for example:
Say I have a whole bunch of apps which use my personal library currently at version 1. When I update my library to say version 2 I'd like, when I run build tasks for all my apps, to have Gradle check on some external location (say git repo) if the library version got updated.
If it has been updated i want gradle to automatically handle the updating of the version number and pulling in the correct version.
Quite simple, just grab the version from your server and dynamically add the version into your dependency's declaration.
def yourVersion = 'http://your-server/version.txt'.toURL().text
dependencies {
compile "your-company:your-lib:$yourVersion"
}

Android grade syntax and build tools compatibility issues

I didn’t work full-time with Android in the last couple of years, and now whenever I try to fork someone code on GitHub I get a lot of errors since android tools and Gradle syntax are changing frequently.
I wonder what is the best way to handle these changes, and be able to upgrade other GitHub projects and some of my old projects to work with the latest Android tools. Here are some of the things that I struggle with:
I noticed some of the issues are related to changes in the Gradle syntax. How can I know what Gradle version the build.grade syntax was written with? and then how to upgrade it to the current version (is there a migration guide for Gradle versions?).
Sometimes I get issues related to tools that are not compatible with others, how can I know which version are compatible with which? and whats the easy way to manage that? here are some of these tools:
Gradle
Android Plugin for Gradle
Build Tools
Android Studio
How can I know what Gradle version the build.grade syntax was written with?
If the project contains a gradle/wrapper/gradle-wrapper.properties file, that is the version of Gradle that the developer of the project is using.
is there a migration guide for Gradle versions?
I am not aware of much Gradle syntax that would have changed that would affect Android developers for garden-variety projects. Most of the changes are from the DSL added via the Gradle for Android plugin. You can find the version of the plugin that the project developer was using via the classpath statement in the project's top-level build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
The above snippet is requesting version 1.3.0 of the Gradle for Android plugin.
Migration documentation for the Gradle for Android plugin is minimal. What there is can be found up on http://tools.android.com.
how can I know which version are compatible with which?
Here is Google's statement on the issue, though this has not been updated in a few months.
and whats the easy way to manage that?
If the tools complain, change them to a set that you know is good (e.g., by copying values from a known-working project). If you need something that was introduced in a newer version of the tools, change them to a set that you know is good. Otherwise, don't worry about them.

Google checkstyle configuration is failing on an Android project

I'm trying to use Checkstyle on an Android project. I figured Googles java coding conventions would be good to use. I'm getting an error when parsing this file:
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
I've looked this error up on stack overflow and it has come up once before, How to compile project with Google Checkstyle rules with gradle?
It seems the error is an older version of checkstyle is pulled down when using gradle. So my question is, is there just an older checkstyle configuration file I can use that's made for the current version of checkstyle pulled down by gradle? Should I even be using Googles java guidelines for an Android project? Is there a better default file to work with? I really don't want to import a new version of checkstyle into my project as mentioned in the answer of the other SO question.
You should always specify the exact version of Checkstyle that you want to use. The Checkstyle guys often make breaking changes which would fail your build unless you set a specific fixed version. For example:
checkstyle {
configFile file('downloaded_google_checks.xml')
toolVersion '6.9' // set Checkstyle version here
showViolations = true
}
Then, you can also use the right configuration file for your version, for example: https://github.com/checkstyle/checkstyle/blob/checkstyle-6.9/src/main/resources/google_checks.xml. Note the version number in the URL - this can be adjusted to the version you selected in your Gradle config.
Do not use the latest configuration file from the master branch, as this matches the current code on the master branch (which is not released yet).
The above allows you to adjust the configuration as necessary. If you are certain that you want the original rule file, you may also follow #BenMane's suggestion from his comment, which is to reference the bundled google_checks.xml directly.

Can't update gradle plugin to 1.3.0-beta4 in Android Studio 1.3

While exploring new API's and features shipped with Android "M", I came across new data binding framework. So, I followed step-by-step guide from Android Authority and Android Developer's post to see this in action. To use data binding, project requires gradle plugin 1.3.0-beta4.But if I try to update, it gives me error something like this:
Error:(1, 0) Plugin is too old, please update to a more recent version,
or set ANDROID_DAILY_OVERRIDE environment variable to
"c70732ebe5710634c90aa6755f18c037274b3dac".
Could someone explain me how to resolve this issue?
As mentioned in comments, you need to modify your gradle file to remove beta4 word, the new line should be like:
classpath "com.android.tools.build:gradle:1.3.0"

Categories

Resources