how to choose the right library version - android

maybe it is because I don't understand it but choosing the right version of dependency libraries to specify in the build.gradle file is a big mess.
How do we know which versions to choose and which versions are compatible with other versions?
Now that I have discovered maven.google.com I think I can see all the versions available to me.
Most recently I am dealing with Firebase libraries. I need both messaging and core. At this writing messaging is at 17.3.4 and core is at 16.0.4. But if I build with those versions I get an error that says cannot access zzbfm - what ever that is.
I finally got a clean compile with the following but this combination was achieved by trial and error taking an hour or so...
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.firebase:firebase-core:16.0.3'
It would be nice if the answer were "always use the latest version" but that certainly isn't the answer.
What am I missing here?

You are not really missing anything. Version compatibility is mainly a thing of trial and error. What you can do:
Only add the artifacts you really use in your code. Don't add transitive dependencies.
Look at potential conflicts in the transitive dependencies and make trials, starting with the newer version.
Generally: Try to use as few dependencies as possible, this reduces the hassle.

Related

Android get latest AOSP commits into my project

My Android application faced some freezing issues in some rare scenarios. After some research I found that this issue was caused by an Android bug which already was reported at issuetracker.google.com. Recently I got notified that the issue was fixed.
Now my question is, how do I make sure that this commit to AOSP that should presumably fix the freezes is already included in my project? It might have something to do with the build.gradle file, which looks like this:
dependencies {
implementation 'androidx.preference:preference:1.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
...
}
For every implementation, a version number exists. So do I have to wait until Google releases the latest version of the package in which the fix is included and then use this latest version? Or will I get the latest fix just by resyncing the project?
I apologize if this is a stupid question, but I did not quite understand yet how the sync between the AOSP repository and my Android project works. Thanks in advance for any help.
Link to the Bug on Issuetracker. It is required to log in with a Google Account to view the Issuetracker.
I would say 'androidx.appcompat:appcompat:1.2.0-alpha03'.
From the Issue Tracker we learn the link to the Patch that fixed the bug. In the patch page, we see the fix is in the 'appcompat' folder/library (the list of modified files at the bottom). Also, in the top-left, we see the repository and the branch where the patch was merged (repo platform/frameworks/support, branch androidx-master-dev). It is important that the patch is marked as MERGED. Only merged patches are integrated into released libraries.
Clicking on the branch link sends us to the repo/branch from which all androidx.* libs are built (See these instructions how to build androidx.* libs yourself and use them locally). Here we have to search for the patch that fixed that bug but the androidx repository receives a lot of patches and the list is pretty long. Fortunately, that search/filter box from top-right accepts a directory key. By adding 'directory:appcompat' in the search box we see only the patches from appcompat lib. It is easy to spot the 'Fix stopped Activities not resuming on < API 24' patch and right above it another patch 'Bump AppCompat version to 1.2.0-alpha03' that sets the version for the fixed appcompat lib.

appcompat-v7:28.0.0-rc02 doesn't work with design:28.0.0-rc01(should be rc02, but we can't)

com.android.support:appcompat-v7:28.0.0-rc02
com.android.support:design:28.0.0-rc01 -> should be rc02, but there's no rc02 actually.
error:
app/build.gradle:74: Error: All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes).
Found versions 28.0.0-rc02, 28.0.0-rc01. Examples include com.android.support:animated-vector-drawable:28.0.0-rc02 and com.android.support:cardview-v7:28.0.0-rc01 [GradleCompatible]
I know it's a warning, we have turned to warn as the errors in CI in order to avoid the potential dead crashes, well, any solution except turn off option for CI?
issue
UPDATE
Design library version 28.0.0-cr02 published.
OLD ANSWER
According to this link
https://mvnrepository.com/artifact/com.android.support/design?repo=google
design:28.0.0-rc02 not yet published.
So all you can do for now is use the previous version for appcompat and wait until design library new version28.0.0-cr02 release.
So for now use this :
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
I don't know why... But they(sdk devs) behaving like Microsoft..
"Ohh..It compiles, lets ship it".
They just launch and don't care about bugs.. after updating to latest libs every time, first thing i get is..
"Layout editor preview errors.".
i hope it will be easy next time. :/
Keep track of the library here, until its published, use rc01 for other ones.
https://mvnrepository.com/artifact/com.android.support/design?repo=google
That's why I use stable versions always
If you are developing an app, you don't want to face these type of errors.
At the time of answering the current most stable version is 27.1.1 and second 28.0.0-rc02.
I suggest use 27.1.1 until 28 stable version release.
implementation 'com.android.support:appcompat-v7:27.1.1'
Sync again
No need of Invalidate/ Restart, Just restart would be okay. Or closing project and reopening from recent would be faster then restart.
Track the support library release.
Replace your
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
with
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Looks like this should no longer be an issue. Looking at the link below, i think that whatever hiccups were encountered by OP are no longer relevant.
https://mvnrepository.com/artifact/com.android.support/appcompat-v7/28.0.0-rc02
About the error message "All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes)." The solution is outlined here (the answer by João Paulo Paiva).
To rid yourself of the error message, you have to basically include each package name mentioned in the warning - com.android.support:animated-vector-drawable:28.0.0-rc02 and com.android.support:cardview-v7:28.0.0-rc01
Essentially, manually add the following lines to your build.gradle
implementation com.android.support:animated-vector-drawable:28.0.0-rc02
implementation com.android.support:cardview-v7:28.0.0-rc02
You may encounter more such warnings - the solution is to keep subsequently adding the libraries/dependencies mentioned (and updating the version to 28.0.0-rc02 as well) until the warnings go away. I had this issue, and after the first lot, I didn't get any more, but YMMV!
1.Go to project/.idea/libraries folder on your file system and see which libraries are different.
2.You will have to manually include these libraries with the same version in your build.gradle file.
3.Then, sync your project
In Your Case:-
Add This Dependency :-
implements 'com.android.support:cardview-v7:28.0.0-rc02'
Add all dependency with Latest version which shows in error message.
I close this ticket, the problem has been solved that Google has updated design library to 28.0.0-rc02 .

All gms/firebase libraries must use the exact same version specification

All gms/firebase libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 15.0.0, 12.0.1. Examples include com.google.android.gms:play-services-ads:15.0.0 and com.google.android.gms:play-services:12.0.1
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).
android studio is giving me this error. How to solve this error? Here is the image of showing error.
You need to add a resolution strategy in your build.gradle file to tell which version of the library need to be used while building your application. The configuration might look something like this.
configurations.all {
resolutionStrategy {
force 'com.android.support:design:25.3.1'
force 'com.android.support:support-v4:25.3.1'
force 'com.android.support:appcompat-v7:25.3.1'
}
}
Modify as per your requirement of the library version.
As it says itself
Found versions 15.0.0, 12.0.1.
You should use same version for all google gms libraries.
Replace this line
compile 'com.google.android.gms:play-services:12.0.1'
with this
compile 'com.google.android.gms:play-services:15.0.0'
First of all use the whole play service is just wrong unless you really need every single sub-package, but from your screenshot you are already using some sub-package. The use of the whole play service package could means you need multi dex support because you include a lot of not needed methods, Proguard is your friend in this case. So my response is: just remove that line.

Library dependency issues with gradle 3.0.0-alphaX

I have a library project with submodules that include many dependencies that I'd like to pass to the developer's application. For example, module A may include all the necessary appcompat dependencies.
With the migration changes, I've updated all compile cases to api, which should not affect anything. However, I no longer have access to any of the libraries dependencies. I can only use code and references from my library itself.
Is there any way around this?
One of the build gradle files of my library submodules can be found here for reference.
The dependencies:
dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib:${KOTLIN}"
api "com.android.support:appcompat-v7:${ANDROID_SUPPORT_LIBS}"
api "com.android.support:support-v13:${ANDROID_SUPPORT_LIBS}"
api "com.android.support:design:${ANDROID_SUPPORT_LIBS}"
api "com.android.support:recyclerview-v7:${ANDROID_SUPPORT_LIBS}"
api "com.android.support:cardview-v7:${ANDROID_SUPPORT_LIBS}"
api "com.android.support.constraint:constraint-layout:${CONSTRAINT_LAYOUT}"
api "com.mikepenz:iconics-core:${ICONICS}#aar"
api "com.mikepenz:google-material-typeface:${IICON_GOOGLE}.original#aar"
api "com.afollestad.material-dialogs:core:${MATERIAL_DIALOG}"
api "com.jakewharton.timber:timber:${TIMBER}"
api "org.jetbrains.anko:anko-commons:${ANKO}"
}
Edit:
To clarify, the sample project in the module actually does build properly, but there's an issue with using the dependencies in any other app, where it pulls from jitpack. See this gradle as an example that won't build.
I've tried using combinations of api, implementation, #aar, and transitive.
Come to think of it, this may be a jitpack issue and not a gradle issue, but if anyone else has a resolution I'd like to hear it.
I no longer have access to any of the libraries dependencies. I can only use code and references from my library itself.
It is correct.
From the gradle docs :
dependencies {
api 'commons-httpclient:commons-httpclient:3.1'
implementation 'org.apache.commons:commons-lang3:3.5'
}
Dependencies appearing in the api configurations will be
transitively exposed to consumers of the library, and as such will
appear on the compile classpath of consumers.
Dependencies found in the implementation configuration will, on the
other hand, not be exposed to consumers, and therefore not leak into
the consumers' compile classpath. This comes with several benefits:
dependencies do not leak into the compile classpath of consumers anymore, so you will never accidentally depend on a transitive
dependency
faster compilation thanks to reduced classpath size
less recompilations when implementation dependencies change: consumers would not need to be recompiled
cleaner publishing: when used in conjunction with the new maven-publish plugin, Java libraries produce POM files that
distinguish exactly between what is required to compile against the
library and what is required to use the library at runtime (in other
words, don't mix what is needed to compile the library itself and what
is needed to compile against the library).
The issue seems to be related to the android-maven-gradle-plugin
Issue Report
It's has been fixed in version "2.0" of android-maven-gradle-plugin
just update to
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
or using the new syntax since Gradle 2.1
plugins {
id "com.github.dcendents.android-maven" version "2.0"
}
using api in your library module allows you to access the transient dependencies only in your library code; not the apps that consume it.
so to achieve the desired effect you need to change in your sample module.
implementation project(':core')
to
api project(':core')
note you don't need to use api in your library it's better to use implementation as it speeds up your build.

Lint GradleCompatible and dependencies

Some dependencies like com.android.support libraries must use the same versions in all libraries. The lint error GradleCompatible states that there can be runtime crashes if the versions differs.
This Lint check has been around for a while, I did no see it in the project I work on until recently, maybe support lib 25.0
The dependencies may not always be in sync with the version in the main project and eachother. This is a problem where the dependencies cannot be controlled.
In the project RunnerUp there are two projects that are open source and can be compiled manually (MapBox, GraphView) - assuming that the dependencies can be updated or downgraded. However there are two Google dependencies that uses separate versions: com.google.android.support:wearable:1.4.0 (23.0.1) and com.google.android.gms:play-services-wearable:10.0.1 (24.0.0)
How should GradleCompatible be handled, is there any solution or should the error just be suppressed?
A little more info in a pull request for an attempt to workaround (maybe without any effect).
https://github.com/jonasoreland/runnerup/pull/519
Edit: It seem like adding the offending support libraries will cause the libraries to be compatible.
Snippet (see PR for details).
app:
//support-v4 is not used by app source but wearable, mapbox
//force same version as in the app
latestCompile "com.android.support:support-v4:${rootProject.ext.supportLibrary}"

Categories

Resources