“Failed to resolve: com.android.support:support-v4

2019-02-04 04:30发布

问题:

This question already has an answer here:

  • Failed to resolve: com.android.support:cardview-v7:26.0.0 android 23 answers

I have just created a new Android Studio project for both Android Mobile and wear. The initial gradle build failed because I am getting several errors-

Error: Failed to resolve: com.android.support:support-v4:26.0.0

Error: Failed to resolve: com.android.support:percent:26.0.0

Error: Failed to resolve: com.android.support:recyclerview-v7:26.0.0

Error: Failed to resolve: com.android.support:support-annotations:26.0.0

With each error, I am given the option to Install repository and sync project, but nothing happens when I click on it. I have spent several hours trying to find why I am getting these errors, but I can't find any solutions. Does anybody know how to fix these very frustrating errors? Thank you!

build.gradle (project)

// 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"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

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

allprojects {
    repositories {
        jcenter()
    }
}

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

build.gradle (mobile)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.georgeberdovskiy.androidweartest"
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-   core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    wearApp project(':wear')
    compile 'com.google.android.gms:play-services-wearable:11.0.4'
    compile 'com.android.support:appcompat-v7:26+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile "com.android.support:support-core-utils:26+"
    testCompile 'junit:junit:4.12'
}

build.gradle (wear)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.georgeberdovskiy.androidweartest"
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    provided 'com.google.android.wearable:wearable:2.0.4'
    compile 'com.google.android.support:wearable:2.0.4'
    compile 'com.google.android.gms:play-services-wearable:11.0.4'
    compile "com.android.support:support-core-utils:26+"
}

I am sure that my version of Android Studio is updated, and all support repositories and APIs are installed.

回答1:

I don't have an Android wear project, but I had the same problem when I wanted to upgrade the Support Library version for an existing project to 26.0.0. Since 26.0.0 the support libraries are available through Google's Maven repository. So I had to add the repository to my build. gradle file.

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

Check out https://developer.android.com/topic/libraries/support-library/setup.html for more details.



回答2:

The following worked for me:

In the Application build.gradle considered to add following:

allprojects {
repositories {
    maven {
        url "https://maven.google.com"
    }
}
}

in the Module build.gradle:

compileSdkVersion 26
buildToolsVersion "26.0.1"

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:support-compat:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:26.0.1'
compile 'com.android.support:support-vector-drawable:26.0.1'
compile 'com.android.support:animated-vector-drawable:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:percent:26.0.1'
compile 'com.android.support:wear:26.0.1'
compile 'com.google.android.support:wearable:2.0.4'
provided 'com.google.android.wearable:wearable:2.0.4'
}


回答3:

Either change your build tool version from 26.0.1 to 26.0.0 or you can replace 26.0.0 by 26.+ like below.

compile 'com.android.support:support-v4:26.0.0'

to

compile 'com.android.support:support-v4:26.+"

Do same with all... Hope it helps. Happy Coding! ^_^



回答4:

For now, I fixed this with changing in the wear build.gradle:

compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'

It seems like the problem is com.google.android.support:wearable:2.0.4. With that, Using 26.0.1 build tools compiles fine. I haven't gone any further with this but it looks like a dependency problem related to a repository although that is really just a guess from the error messages.



回答5:

Add following dependency in your gradle

Replace

    compile 'com.android.support:support-v4:26.0.0'

with

   compile 'com.android.support:support-v4:25.0.0'

and Replace

   compile 'com.android.support:appcompat-v7:26+'

with

compile 'com.android.support:appcompat-v7:25.0.0'


回答6:

Add the following dependencies in your app/build.gradle.

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven{url 'https://maven.google.com'}
}


回答7:

Replace this:

    compile 'com.android.support:recyclerview-v7:26.0.0'

With this

    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'

Do same with all

Update - new version released

    compile 'com.android.support:recyclerview-v7:26.1.0'


回答8:

The reason that my project was giving me these errors was because I created the project for Android Platform 26. However, Wear currently doesn't support 26, and it is essential to change the target and compile SDK versions to 25 in the wear module of build.gradle.

Link to Android Developers documentation - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone

build.gradle (wear)

apply plugin: 'com.android.application'


android {
compileSdkVersion 25
buildToolsVersion "26.0.1"

defaultConfig {
    applicationId "com.georgeberdovskiy.findmyphone"
    minSdkVersion 25
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),       'proguard-rules.pro'
    }
    }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'

}

apply plugin: 'com.google.gms.google-services'

I only needed to change the compile and target SDK versions to 25 in the wear module. I left them as 26 for the mobile module.



回答9:

This one worked for me

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

google() does the magic with the following configuration

Studio version : 3.0 beta 2

classpath 'com.android.tools.build:gradle:3.0.0-beta2'

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip


回答10:

I meet this problem, changing the build tool/ sdk version didn't work, clearly write compile version didn't work, off line build didn't work.

Finally I just change wearable version, and this problem gone.

provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'

to

provided 'com.google.android.wearable:wearable:2.0.2'
compile 'com.google.android.support:wearable:2.0.2'

By the way, I used offline building now because it is really fast when I check this issue.