Gradle构建失败,错误无法解析:com.android.support
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gradle构建失败,错误无法解析:com.android.support相关的知识,希望对你有一定的参考价值。
我正在尝试构建旧代码,但gradle
同步失败给出错误:
无法解决:com.android.support。
我已经研究过这个问题并尝试在我的代码中实现它们,但是它们中的任何一个都没有用。我的gradle
看起来如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.tex"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':slideMenuLibrary')
implementation('com.github.nkzawa:socket.io-client:0.3.0') {
exclude group: 'org.json', module: 'json'
}
implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support.constraint: constraint-layout: 1.0.2'
implementation 'com.google.android.gms:play-services-maps:10.2.1'
implementation 'com.google.android.gms:play-services-analytics:10.2.1'
implementation 'com.google.android.gms:play-services-gcm:10.2.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.koushikdutta.ion:ion:2.+'
implementation 'com.android.support:design:27.1.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.victor:lib:1.0.4'
implementation 'com.afollestad.material-dialogs:core:0.8.6.2'
implementation 'com.github.lzyzsd:circleprogress:1.1.0@aar'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.wdullaer:materialdatetimepicker:2.4.0'
implementation 'org.apache.commons:commons-lang3:3.3.2'
androidTestImplementation 'junit:junit:4.12'
}
我的项目build.gradle文件如下所示:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
该库的gradle文件如下:
buildscript {
repositories {
google()
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
apply plugin: 'com.android.library'
dependencies {
implementation 'com.android.support:support-v4:27.1.1'
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
答案
在allprojects中的根build.gradle文件中添加以下内容:
repositories {
mavenLocal()
mavenCentral()
maven { // <-- Add this
url 'https://maven.google.com/'
name 'Google'
}
}
如果你正在使用Android插件Gradle 3.0.0或更高版本
repositories {
mavenLocal()
mavenCentral()
google() //---> Add this
}
并以这种方式注入依赖:
implementation 'com.android.support:appcompat-v7:27.1.1'
以上是关于Gradle构建失败,错误无法解析:com.android.support的主要内容,如果未能解决你的问题,请参考以下文章
> 无法解析 com.android.tools.build:gradle:3.5.0
android studio firebase 错误:“无法解析 Android 应用程序模块的 Gradle 配置。解决 gradle 构建问题和/或重新同步。”