web-dev-qa-db-fra.com

Comment puis-je corriger ces erreurs concernant l'impossibilité de trouver des dépendances lors de la compilation d'un projet sous Android?

Je reçois ces erreurs lorsque j'essaie de construire mon projet, on dirait que je pense avoir 2 bibliothèques identiques, mais je ne sais pas pourquoi:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.Android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.Android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.Android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.Android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.Android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.Android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.room:room-testing:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.Android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.Android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.Android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.Android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.room:room-testing:2.1.0-alpha02.
Open File
Show Details

Ceci est mon fichier build.gradle

apply plugin: 'com.Android.application'

Android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
    applicationId "com.andydaykin.timer"
    minSdkVersion 24
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-Android.txt'), 
'proguard-rules.pro'
    }
    dexOptions {
        // release & debug is in project animators
        matchingFallbacks = ['release', 'debug']
    }
    debug {
        debuggable true
    }
}
compileOptions {
    targetCompatibility 1.10
    sourceCompatibility 1.10
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven { url 'https://maven.google.com' }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'

implementation ('androidx.legacy:legacy-support-core-utils:1.0.0') {
    force = true
}
implementation 'androidx.appcompat:appcompat:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'com.google.guava:guava:24.1-jre'
implementation 'com.google.inject:guice:4.1'
implementation 'com.google.firebase:firebase-appindexing:16.0.2'
implementation 'com.google.Android.gms:play-services-analytics:16.0.5'
implementation 'com.google.Android.gms:play-services-ads:17.0.0'

implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"

def room_version = "2.1.0-alpha02"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

testImplementation "androidx.room:room-testing:$room_version"
}

Ceci est mon fichier de construction de premier niveau:

{

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
}
    dependencies {
        classpath 'com.Android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they 
belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

}

Je pense que cette erreur est survenue après une mise à niveau vers le studio Android, mais je ne m'en souviens pas avec certitude. La version de mon studio Android est maintenant 3.2.1. J'ai pu obtenir ce projet à construire précédemment.

6
Andy

Dans votre fichier Gradle de niveau supérieur, ajoutez un chemin de classe pour Google Service Plugin.

dependencies {
    classpath 'com.Android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.0.1'
}

_ {vous devriez vérifier votre connexion Internet, votre proxy ou votre pare-feu.} _

OU

cochez la case pour désactiver Gradle hors ligne en suivant.

Les fenêtres:

Paramètres> Gradation> Désactiver le travail hors connexion

Mac: 

Préférences> Génération, Exécution, Déploiement> Graduation> Désactiver le travail hors connexion

 enter image description here

1
Muzammil Husnain

Si vous utilisez Android Studio 3+ et Gradle version 4. +, alors maven n’est pas nécessaire . Essayez de supprimer 

        maven {
            url 'https://maven.google.com/'
            name 'Google'
             }

et juste avoir,

    buildscript {
    repositories {
        google()
        jcenter()

}
    dependencies {
        classpath 'com.Android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()    
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
0

Aussi, vérifiez ici: https://stackoverflow.com/a/53716633/8034839 et React Native: Impossible de trouver com.Android.tools.build:gradle:2.2.3
Il est lié à la migration AndroidX. 

Essayez la solution ci-dessous depuis https://developer.Android.com/jetpack/androidx/migrate

Migrer un projet existant à l'aide d'Android Studio

Avec Android Studio 3.2 et versions ultérieures, vous pouvez migrer rapidement un projet existant pour utiliser AndroidX en sélectionnant Refactor> Migrate to AndroidX dans la barre de menus.

Si vous avez des dépendances Maven qui n'ont pas été migrées vers l'espace de noms AndroidX, le système de génération d'Android Studio migre également ces dépendances lorsque vous définissez les deux indicateurs suivants sur true dans votre fichier gradle.properties:

Android.useAndroidX=true
Android.enableJetifier=true

Pour migrer un projet existant qui n'utilise aucune bibliothèque tierce avec des dépendances à convertir, vous pouvez définir l'indicateur Android.useAndroidX sur true et l'indicateur Android.enableJetifier sur false.

De plus, dans votre TOP-NIVEAUbuild.gradle, tirez la google() vers le haut comme ci-dessous: 

allprojects {
    repositories {
        google() // here
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        //google()
    }
}
0
shizhen

Je pense que cette erreur est survenue après une mise à niveau vers le studio Android

Le problème ne faisait que commencer lorsque vous avez modifié compiler en implémentation .


Supposons que A, B et C sont trois modules et que la relation entre eux est la suivante

C>B>A > Représente une dépendance


Lorsque vous utilisez compile , C peut accéder directement à A. Mais ce n’est pas possible lorsque vous utilisez implementation . Il y a api qui aura le même effet que compiler.


Note: Il n'est pas recommandé d'utiliser api partout. api et compile ralentiront le processus de compilation car il obligera à recompiler tous les modules de bas niveau pour lesquels la mise en œuvre ne recompilera que les modules requis lorsqu'un module de niveau supérieur est modifié.

0
Anees