Android Studio第一个项目;Failed to resolve: com.android.support:appcompat-v7:28.0.0

2019年1月26日

按照网上教程下载安装Android Studio后照着第一行代码创建第一个项目,遇到以下报错

ERROR: Failed to resolve: com.android.support:appcompat-v7:28.0.0
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.constraint:constraint-layout:1.1.3
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test:runner:1.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: junit:junit:4.12
Show in Project Structure dialog
Affected Modules: app

错误均指向app文件下的build.gradle

试了博客上种种办法均没有成功反而报错越来越多。错误所在均见下图

在看完第一行代码第一章后和这个博客https://blog.csdn.net/mhl18820672087/article/details/78385361/后有了新的理解

检查File->Settings->Android SDK和updates,SDK Tools中相对应的版本信息是否一致

勾上Show Package Detial

我的build-tool28.0.3版本,SDK tool为26.1.1,API 28

可以知道SDK tool与SDK build-tool版本不对,build-tool版本太高

第一次尝试

将代码改为如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

失败。提示:

ERROR: Failed to find Platform SDK with path: platforms;android-26

安装Android-26,后Sync Project再次尝试,失败:

ERROR: Failed to resolve: com.android.support:appcompat-v7:26.0.0
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.constraint:constraint-layout:1.1.3
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test:runner:1.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: junit:junit:4.12
Show in Project Structure dialog
Affected Modules: app

改此处代码,再尝试

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

报错:

ERROR: Failed to resolve: com.android.support.constraint:constraint-layout:1.1.3
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test:runner:1.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: junit:junit:4.12
Show in Project Structure dialog
Affected Modules: app

查看SDK manager版本信息改此处代码后再次尝试:

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

依然报错,可喜可贺错误信息在变少:

ERROR: Failed to resolve: com.android.support.test:runner:1.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.2
Show in Project Structure dialog
Affected Modules: app


ERROR: Failed to resolve: junit:junit:4.12
Show in Project Structure dialog
Affected Modules: app

百度了很多次,没有找到一个可以解决我问题的方法。干脆直接删除了这些东西。

如果有人知道如何解决请告诉我,感激不尽。

再次点击Sync Project即成功了。并成功在模拟器上安装了第一个程序“HelloWorld”

最后版本为:

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

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

猜你喜欢

转载自blog.csdn.net/stone_fall/article/details/86660649