今天,简单讲讲Android studio编译报错:Failed to resolve: com.android.support:appcompat-v7:28.+的问题。
这个问题其实之前遇到过,今天又遇到了。所以记录一下。
总的来说,就是Android studio的SDK工具版本低于工程需要的SDK工具版本,SDK Build-Tools与工程所需的不一致。具体讲解如下:
具体解决方案:
1.既然是版本问题,那就的先去了解自己的电脑安装的SDK工具版本,点开SDK Manager图标,然后选中Updates就可以看到了
这里我的 sdk 工具版本就是26.1.1了
2.清楚了自己的sdk 工具版本后,接下来我们继续查看版本,接下来是看sdk 构建工具(sdk Build-Tools)的版本,还是在sdk manager上操作,这次选中 Android SDK后,再在右边选中SDK Tools(只看打勾选项就行)
看了这张图,似乎就能明白些什么了对吧,你会发现,我这里是的 Android SDK Build-Tools (就是我前面一直提到的sdk 构建工具)版本是27,而我的SDK Tools才是26,
很明显版本就低了,但这些并不会直接造成项目报错,看完这些数据,我们接下来再看一张截图
3.点开项目构建文件Gradle Scripts,再继续点击build.gradle(Module:app)ps:有两个名字相同的,选第二个,看下面代码的注释行就可以了
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.a28055.myapplication"
minSdkVersion 15
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'
})
compile 'com.android.support:appcompat-v7:28.+'
testCompile 'junit:junit:4.12'
}
我们来分析下appcompat-v7:27.+
上面我们查到我们的sdk工具版本是26,这里的远程依赖包的版本是27,那么我们只需要将把版本减低到和sdk工具版本相同就ok啦!
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.a28055.myapplication"
minSdkVersion 15
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'
})
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
}
其实就是修改compileSdkVersion为Android studio SDK工具的版本,修改compile 'com.android.support:appcompat-v7:26.+'为SDK工具的版本。我的SDK工具是26,所以这样修改。
Android 解决: Failed to resolve: com.android.support:appcompat-v7:28.+ 错误就讲完了。、
就这么简单。