Specify Android Lint version - android

How do I specify the version used for Android Lint? From the lint report: <issues format="5" by="lint 3.5.3">

Lint is a part of ADT(Android Development Tools) and more specifically it depends on the Android Gradle Plugin Version. You cannot change Lint version independently from gradlePluginVersion. When you change gradlePluginVersion, Lint version will be changed automatically to the corresponding one from current version of the plugin.
If you want to disable some checks or write your own rules you may check this. Also you may create your own 'Lint' modules using "com.android.tools.lint:lint-api:$lintApiVersion"
and "com.android.tools.lint:lint-checks:$lintApiVersion" compileOnly dependencies from here
Hope it helps

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.

What is the correct way to move gradle dependency versions to a variable?

In order to maintain the version numbers of my gradle dependencies, I chose the below pattern.
In my project level build.gradle I added:
ext.versions = [
'kotlin_version' : '1.2.30',
'dagger' : '2.16'
]
And in my app module's build.gradle I added:
implementation "com.google.dagger:dagger:${versions.dagger}"
implementation "com.google.dagger:dagger-android-support:${versions.dagger}"
implementation "com.google.dagger:dagger-android:${versions.dagger}"
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"
kapt "com.google.dagger:dagger-android-processor:${versions.dagger}"
But my problem is after doing this, I lost the lint warnings of "Newer Library versions available".
What is the correct way to do this without missing the lint checks?
Note: I have also tried other ways like moving these versions to gradle.properties file (for global variables).
I am looking for a solution inside Android Studio. There is one solution which I already found:
Analyze -> Run Inspection by name... -> Type "Newer Library Versions Available"
But my concern is, it is easy to miss on updates until we run some or the other script. That is why I am trying to find a way where dependency versions can be put in a variable and get lint warning for new updates.
See this answer: https://stackoverflow.com/a/46296198/2053763
There is a link to a gradle plugin which can check for dependency updates.
Android Studio 3.1.2 offers some lint checks while using version variables, but still misses some of the updates. See image below:
You can extract dependencies versions into variables stored in a separate Gradle file and then check and update them from the Project Structure (ctrl+alt+shift+S) (screenshot from Android Studio 3.6.3):

How does Gradle choose between more than 1 versions of the same library in a gradle tree?

Let say I have added Facebook and Twitter dependencies in my app.
com.facebook.android:facebook-android-sdk:4.22.1
com.twitter.sdk.android:twitter:2.1.0
When i look at Gradle tree, They come up with bunch of other transitive dependencies.
Now If Facebook uses com.android.support:support-annotations:24.1.1 and twitter uses com.android.support:support-annotations:25.0.3
Then which version gradle will use.
In gradle tree, It shows -> in front of older version of dependency. I learnt that this means gradle will use the newer version, and will not use the older version.
But this can be a problem, because some libraries are meant to run on the specific versions, and i have faced this problem.
In one of article i found out how npm manages these dependencies conflicts, but i am still unsure how gradle will manage between different version of same library.
You can't have different versions of the same library inside an apk.
As you mentioned, by default, Gradle puts the newest one to the build. If you want to specify a concrete version of the library that should be used in your project, you can add a direct compile (or implementation / api for Android Gradle Plugin v3+) statement with a required version to get one.
Also, you can force version using a special syntax, but it can lead to some problems later. You can find more information about version conflicts resolution in this post

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.

How to update Gradle dependencies to their latest version

Is there an easy way to get gradle to update dependencies to their latest available version?
For build reproducibility all my dependencies are defined with a version number like this in my build.gradle file:
dependencies {
compile 'namespace:package1:version'
compile 'namespace:package2:version'
compile 'namespace:package3:version'
}
Periodically I want to update every package to their latest version. Typically this is the first thing I do for a new sprint after making a release.
It's a real pain doing this manually for each package. Ideally I would like a command to update the build.gradle file for me but at the very least a command that prints out which package needs an update and what the latest version number is.
In ruby land I would run bundler update.
This is all I've been able to come up with. I will happily accept another answer if there is a less manual method of doing this.
In Android studio I replace every dependency version with a plus example: compile 'namespace:package1:+'
Sync or build the project which will cause all the dependencies to be resolved to their latest version.
In Android Studio place the cursor on each dependency line in build.gradle and press alt+enter a menu pops up and you can select Replace with specific version
Add to build.gradle:
plugins {
id 'com.github.ben-manes.versions' version '0.17.0'
}
Then you can do gradle dependencyUpdates to get a report of new versions. Unlike the eponymous Maven plugin, there doesn't seem to be a way of automatically updating the build.gradle yet.
More documentation: https://github.com/ben-manes/gradle-versions-plugin
It is not a really good practice as libraries can include changes that may break your code.
A common "tolerated" syntax for
compile 'namespace:package:major_version.minor_version.revision'
would be like
compile 'namespace:package:1.0.+'
considering revision is used by the library authors as bug fixes and improvements updates
Note:
I just did that and you could do
compile 'namespace:package:+'
Edit:
A Proof Of Concept of my latest comment you may want to test.
This was made in 5 minutes, so don't expect it to be perfect nor flexible.
I suffer from it, too. And the best way to check dependencies, even manually, is to go through Project Structure and search for the dependency name and see if there is a newer version.
The problem that this query only checks for the dependencies present in the Maven repository. At least it already goes for Google's.
Note: If you choose to add the dependency with the new version, this will add a duplicity in the your App Gradle, so be sure to delete the old dependency row.
###################
Another possible quick fix is through the command line:
./gradlew app:dependencies
This will generate an output like the one below. Note that the asterisk points to a possible new existing version.

Categories

Resources