Android Studio第一个项目 | 报错处理 | Failed to resolve: com.android.support:appcompat-v7:28.0.0

以下报错可以通过翻墙和挂镜像让AS自行处理。是版本和包的不完整所导致的。

 

(原文)


按照网上教程下载安装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'
}

 

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值