错误:无法解析':app @ debug / compileClasspath'的依赖项:无法解析com.android.support:appcompat-v7:26.0.0-beta1

时间:2017-12-23 13:47:12

标签: android

我有android studio 2.3.3,我安装了android studio 3.0.1。我无法同步项目

这是我的错误:

E:\AndroidProject\...\app\build.gradle
    Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.0.0-beta1. Open File Show Details

Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.0.0-beta1.

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.0-beta1. 
....

我的应用build.gradle

    apply plugin: 'com.android.application'
            android {
        compileSdkVersion 26
        buildToolsVersion '26.0.2'
        defaultConfig {
            applicationId "com.avana.xxx"
            minSdkVersion 14
            targetSdkVersion 26
           ...
        }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
    compile 'com.android.support:appcompat-v7:26.0.0-beta1'
    compile 'com.android.support:cardview-v7:26.0.0-beta1'
    compile 'com.android.support:design:26.0.0-beta1'
}

build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

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

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

gradle.wrapper

  distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

2 个答案:

答案 0 :(得分:4)

转到setting->build->gradle,然后取消选中offline-work按钮。然后重建你的程序。

这是same problem as yours

答案 1 :(得分:0)

最后我通过消耗3个小时并修改build.gradle来解决这个问题:

第1步:第一次更改build.gradle(模块:应用)

apply plugin: 'com.android.application'
android {
compileSdkVersion 26

defaultConfig {
    applicationId "com.testapp"
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 2 
    versionName "1.1" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }

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

dependencies { // Below lines are for reference only
   implementation fileTree(include: ['*.jar'], dir: 'libs')
   implementation 'com.android.support:appcompat-v7:26.1.0'
   implementation 'com.android.support:support-v4:26.1.0'
   implementation 'com.android.support:design:26.1.0'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.1'
   androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

第2步: build.gradle中的另一项更改(Project:testApp),这是非常重要的更改,您已完成:)

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'

    }
}

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

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