Search code examples
androidwear-osandroid-wear-2.0

Error:Failed to resolve: wearable


I have an existing project and when I try to add a wear module to it, the error below is shown. When I create a new project with a wear module it's working.

Error:Failed to resolve: wearable

and

project depends of com.google.android.support:wearable:2.3.0 so it must also depend com.google.android.wearable:wearable:2.3.0

error screenshot

enter image description here


Solution

  • You need to add a provided like this

    ...
    provided 'com.google.android.wearable:wearable:2.3.0'
    implementation 'com.google.android.support:wearable:2.3.0'
    ...
    

    Also check that your project level build.gradle has the google repository, I think some wearable libs now come from google rather than jcenter.

    buildscript {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
            flatDir {
                dirs 'libs'
            }
        }
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:deprecation"
        }
    }