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.
I don't really understand why my appcompat version is not accepted
Please help
click to see image
This is a warning, your app will still run.
One or more of your transitive dependencies is requesting different version of of the Android Support Library that you are not requesting directly yourself, resulting in this conflict. You will need to run a Gradle dependency report and find out what is causing the problem, then manually request those artifacts yourself with your desired version (presently, 27.0.1).
I think in your case facebook is using old version, you should try updating facebook dependency version to latest.
You can see this answer as well.
You have probabelly some libraries that use older versions of some others support libraries (not especially AppCompat), so you have to override them manually in the gradle to get rid of this warning.
You have to repeat this until the warning disapear :
When you see the hint, copy and past the library and update the version number : for example if in the hint you have
"blablabla... example include blablabla...
com.android.support:support-core-ui:26.0.1"
Add this to the dependencies section of the build.gradle script :
implementation 'com.android.support:support-core-ui:27.1.1'
In my project I have many libraries defined in dependencies section in gradle. Problem is once in a while (once/twice a day)Android Studio gives me errors like this when opening the project or trying to get a release output:
Error:Unable to resolve dependency for ':TMessagesProj#armv7Debug/compileClasspath': Could not resolve com.google.android.gms:play-services-gcm:11.2.+.
My guess is it is because build tools is trying to check if there is an update for each library and when it doesn't find an Internet connection, it shows this error. If so, how can I change the setting in a way it doesn't have to check for updates? In other words in my project I don't need to update my libraries.
I know there is an offline mode that will probably do the trick! But I don't want to use this feature because it will probably disable some other useful features too. I just want to prevent it from automatically checking for library updates(If that's the problem shown above).
I included some part of my dependencies in gradle here:
dependencies {
compile 'com.google.android.gms:play-services-gcm:11.2.+'
compile 'com.google.android.gms:play-services-maps:11.2.+'
compile 'com.google.android.gms:play-services-vision:11.2.+'
compile 'com.google.android.gms:play-services-wallet:11.2.+'
}
Dependencies with a plus like 11.2.+' will always lead to repeated builds.
You have to specify the full version like:
com.google.android.gms:play-services-gcm:11.2.0
If you do not specify gradle will always be building because its looking for the latest version online of 11.2.+ may be 11.2.4, 11.2.6 etc
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
I've always added dependencies like this:
dependencies {
compile 'com.android.support:mediarouter-v7:19.+'
}
but in the recent versions of Android Studio, they recommend not to use the + as it can lead to errors. How to know what's the latest version? I can try every combination of 19.y.x until gradle complains, but what's the real way do check?
edit: sometimes, that page helps me figure it out.
There may be other ways, but here is what i use:
You can find out the latest version using Android Studio by replacing the version number of your library in build.gradle compile line, with just + , and click on Sync Now in upper right corner of the window.
in your case, for example
dependencies {
compile 'com.android.support:mediarouter-v7:+'
}
Android Studio will pop up a hint/bulb, which has options Replace with specific version you can click, which will fill-in the latest version in-place of +. Please see below screeshot:
If this doesn't work the first time, let gradle complete its sync, and retry (replace + with + or any file modification will do, click the sync now again and hint bulb will show up).
For example, for your library, i simply pasted this line compile 'com.android.support:mediarouter-v7:+' under my dependencies and followed the above process, Android Studio filled in with below version
Relying on latest version is indeed a dangerous thing to do. Your build can break without you changing anything, just because some library broke backwards compatibility.
The easiest way to know when new version of a library is out is to subscribe to new version notifications in Bintray.
Just click on the "Watch" button on the package page and you'll get an email every time new version is out. Then you'll be able to update the dependency, test it, and only then commit the build script with the new version.
As already mentioned by some other answers you should not use + in dependencies because it may lead to unpredictable builds, so its always better if you first test your builds once a new update is available.
With android studio 2.2 and above Project Structure will show you the latest dependencies available.
Activate it by going to Android Studio > Settings > Build,
Execution, Deployment > Gradle > Experimental and check the Use
new Project Structure dialog
Then open it by going to File >Project Structure > Messages
Original Answer
I use these two links.
This link gives me the latest buildTools Version
https://developer.android.com/studio/releases/build-tools.html
This link gives me the latest supportLibraryVersion
https://developer.android.com/topic/libraries/support-library/revisions.html
Recently, I have found this.
Go to File -> Project Structure
Select the Module, where you want to add the dependency.
Go to the Dependencies Tab
Click + and Choose Library Dependency
Choose whichever Library you need from the list.
(There is also an option for Search, never tried though.)
That's it.
Done.
Thank You.
Avoid to use + in version declare.
You can try andle to check if dependency out of date, also the build tool version and sdk version.
Simple three step:
1. install:
$ sudo pip install andle
2. set sdk:
$ andle setsdk -p <sdk_path>
3. update depedency:
$ andle update -p <project_path> [--dryrun] [--remote]
--dryrun: only print result in console
--remote: check version in jcenter and mavenCentral
the answer of ashoke is correct if you want the latest version.
But if you just want to replace "+" by the version you are currently using (therefor protection yourself against bug in future update)
eg:
compile 'com.android.support:appcompat-v7:21.0.+'
to
compile 'com.android.support:appcompat-v7:21.0.3'
(but not using 23.0.1)
this is the easiest way, no software needed:
run
$ ./gradlew clean tasks --debug > ~/whatever.txt
then look for "com.android.support:appcompat-v7:21.0."
a few line below you will see
"Using com.android.support:appcompat-v7:21.0.3 from Maven repository"
If it is a dependency that comes from Google's maven repository, the best way these days is to go to https://maven.google.com , where google now lets you browse all their libraries and see all the versions available, including the latest version. It looks like this:
You can even do a search for a specific library, and then expand/collapse it as desired: