Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Unable to resolve dependency

I inherited a project from another developer. The project hasn't been touched in a year. When I try to build the project, I get a bunch of "unable to resolve dependency" errors. What do these mean? What is missing from the project? Below are some examples of the build errors I'm getting:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.code.gson:gson:2.8.5.
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.constraintlayout:constraintlayout:1.1.3.
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.jakewharton:butterknife:10.1.0.
Show Details
Affected Modules: app

Hi Eric. Could you share your build.gradle files please? Thanks

Here are the build.gradle files:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.infiswift.snakeriver"
        minSdkVersion 21
        versionCode 11
        versionName "2.0.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        //targetSdkVersion 25
        targetSdkVersion 28
        maxSdkVersion var
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        //added to facilitate build
        dexOptions {
            matchingFallbacks = ['release', 'debug']
        }
    }
    /*compileOptions {
        sourceCompatibility 'JavaVersion.VERSION_1_8'
        targetCompatibility 'JavaVersion.VERSION_1_8'
    }*/
    //buildToolsVersion = '28.0.3'
}

dependencies {

    //exclude group: 'com.android.support', module: 'support-annotations'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
    implementation 'com.jakewharton:butterknife:10.1.0'
    implementation 'com.android.support:support-core-utils:28.0.0'
    implementation 'com.android.support:support-compat:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.afollestad:aesthetic:0.4.7'
    implementation 'com.github.michaelye.easydialog:easydialog:1.4'
    implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.3'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}

...and the second one:

ext {
    var = 28
}

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        //classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.android.tools.build:gradle:3.3.2'

        // 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'
        }
        google()
    }
}

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

1 Answer

Hi Eric. You are using both versions of the support library here: AndroidX and the original Support Library. You even have both versions for ConstraintLayout:

implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
 // (...)
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

You need to choose the support library you want to use and adjust all your dependencies accordingly (making sure all your 3rd party libraries can run on AndroidX if that's what you decide to go with). So the dependencies should start with

- com.android.support:   // if you choose the Support Library
- androidx.    // if you choose the AndroidX library 

Keep in mind that the version 10.* of Butterknife only works with AndroidX, so if you decide to use the original Support Library, you will have to use the version 9.* instead

Also, in your build.gradle file (Project), you do not need the maven repository shortcut there as you already have the google() one which points to the same thing.

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

Hope that helps :)

Thank you for all of your help.

You're welcome :)