Avec un nouveau Android projet Studio créé (type d'activité vide), si vous ajoutez les lignes suivantes:
// Lifecycle/View Models
def lifecycleVersion = '2.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycleVersion"
// Core testing
def coreTestingVersion = '2.0.1'
testImplementation "androidx.Arch.core:core-testing:$coreTestingVersion"
androidTestImplementation "androidx.Arch.core:core-testing:$coreTestingVersion"
Vers l'application build.gradle
fichier, vous verrez des erreurs lorsque vous essayez d'exécuter la tâche connectedCheck
pour le projet. Voir la sortie:
Zachs-MBP:CoreTestingVersionExample Zach$ ./gradlew connectedCheck
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:preDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
> Could not resolve androidx.Arch.core:core-common:2.0.0.
Required by:
project :app
> Cannot find a version of 'androidx.Arch.core:core-common' that satisfies the version constraints:
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-testing:2.0.1' --> 'androidx.Arch.core:core-runtime:2.0.1' --> 'androidx.Arch.core:core-common:2.0.1'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-runtime:2.1.0-alpha03' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata-core:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.appcompat:appcompat:1.1.0-alpha03' --> 'androidx.fragment:fragment:1.1.0-alpha05' --> 'androidx.activity:activity:1.0.0-alpha05' --> 'androidx.savedstate:savedstate:1.0.0-alpha02' --> 'androidx.Arch.core:core-common:2.0.0'
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
> Could not resolve androidx.Arch.core:core-runtime:2.0.0.
Required by:
project :app
> Cannot find a version of 'androidx.Arch.core:core-runtime' that satisfies the version constraints:
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-testing:2.0.1' --> 'androidx.Arch.core:core-runtime:2.0.1'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata-core:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
> Could not resolve androidx.Arch.core:core-runtime:2.0.1.
Required by:
project :app > androidx.Arch.core:core-testing:2.0.1
> Cannot find a version of 'androidx.Arch.core:core-runtime' that satisfies the version constraints:
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-testing:2.0.1' --> 'androidx.Arch.core:core-runtime:2.0.1'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata-core:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
> Could not resolve androidx.Arch.core:core-common:2.0.0.
Required by:
project :app > androidx.lifecycle:lifecycle-extensions:2.0.0
project :app > androidx.lifecycle:lifecycle-livedata:2.0.0
project :app > androidx.lifecycle:lifecycle-runtime:2.1.0-alpha03
project :app > androidx.lifecycle:lifecycle-livedata-core:2.0.0
project :app > androidx.savedstate:savedstate:1.0.0-alpha02
> Cannot find a version of 'androidx.Arch.core:core-common' that satisfies the version constraints:
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-testing:2.0.1' --> 'androidx.Arch.core:core-runtime:2.0.1' --> 'androidx.Arch.core:core-common:2.0.1'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-runtime:2.1.0-alpha03' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata-core:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.appcompat:appcompat:1.1.0-alpha03' --> 'androidx.fragment:fragment:1.1.0-alpha05' --> 'androidx.activity:activity:1.0.0-alpha05' --> 'androidx.savedstate:savedstate:1.0.0-alpha02' --> 'androidx.Arch.core:core-common:2.0.0'
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
> Could not resolve androidx.Arch.core:core-runtime:2.0.0.
Required by:
project :app > androidx.lifecycle:lifecycle-extensions:2.0.0
project :app > androidx.lifecycle:lifecycle-livedata:2.0.0
project :app > androidx.lifecycle:lifecycle-livedata-core:2.0.0
> Cannot find a version of 'androidx.Arch.core:core-runtime' that satisfies the version constraints:
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-testing:2.0.1' --> 'androidx.Arch.core:core-runtime:2.0.1'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata-core:2.0.0' --> 'androidx.Arch.core:core-runtime:2.0.0'
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-runtime' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
> Could not resolve androidx.Arch.core:core-common:2.0.1.
Required by:
project :app > androidx.Arch.core:core-runtime:2.0.1
> Cannot find a version of 'androidx.Arch.core:core-common' that satisfies the version constraints:
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-testing:2.0.1' --> 'androidx.Arch.core:core-runtime:2.0.1' --> 'androidx.Arch.core:core-common:2.0.1'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-runtime:2.1.0-alpha03' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata:2.0.0' --> 'androidx.lifecycle:lifecycle-livedata-core:2.0.0' --> 'androidx.Arch.core:core-common:2.0.0'
Dependency path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.appcompat:appcompat:1.1.0-alpha03' --> 'androidx.fragment:fragment:1.1.0-alpha05' --> 'androidx.activity:activity:1.0.0-alpha05' --> 'androidx.savedstate:savedstate:1.0.0-alpha02' --> 'androidx.Arch.core:core-common:2.0.0'
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'CoreTestingVersionExample:app:unspecified' --> 'androidx.Arch.core:core-common' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Si j'utilise la même valeur lifecycleVersion
et coreTestingVersion
(2.0.0 par exemple), les erreurs ne se produisent pas, mais lint se plaint que les principales dépendances de test ont une version mise à jour (2.0.1). (Au moins, il fonctionne, cependant: P) Je pensais que l'un des avantages de androidx
était qu'il permettrait de mettre à jour des pièces individuelles sans problème?
Voici un exemple d'application montrant le problème: https://github.com/ZOlbrys/CoreTestingVersionExample
Exécutez simplement connectedCheck
via le terminal dans ce projet pour voir l'échec de la construction.
Des idées pour résoudre le problème?
edit: problème google créé pour cela, voir https://issuetracker.google.com/issues/129316035
Pour résoudre ce problème, vous devrez utiliser une stratégie de résolution des dépendances. Voici comment je l'ai résolu lorsque j'ai rencontré un problème similaire: Impossible de trouver la version de 'androidx.Arch', 'androidx.room', etc.
configurations.all
{
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.Arch.core'
&& !details.requested.name.contains('core-runtime')) {
details.useVersion "2.0.1"
}
}
Fyi pour chaque dépendance est représentée par l'implémentation " group *: name: * version "
J'ai dû faire deux solutions pour résoudre ce problème:
Utilisez la dernière bibliothèque de services Google Play: https://developers.google.com/Android/guides/google-services-plugin
Comme mentionné dans d'autres réponses:
configurations.all
{
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.Arch.core'
&& !details.requested.name.contains('core-runtime')) {
details.useVersion "2.0.1"
}
}