无法解决依赖项':app@debug/compileClasspath':无法解析com.android.support:appcompat-v7:28.0.0-rc01

19

我在我的新Android Studio版本中遇到以下错误,基本的Hello world也无法在gradle中构建。你能帮我解决这个问题吗?

下面是我在新版Android Studio中遇到的错误:

This is the error I am getting in new android studio version

我的gradle文件如下所示

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "payments.com.java.payments"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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'
}

这是我收到的日志

无法解决“:app@debug/compileClasspath”的依赖关系:无法解决com.android.support:appcompat-v7:28.0.0-rc01。 打开文件 显示详细信息

无法解决“:app@debug/compileClasspath”的依赖关系:无法解决com.android.support.constraint:constraint-layout:1.1.2。 打开文件 显示详细信息

无法解决“:app@debugAndroidTest/compileClasspath”的依赖关系:无法解决com.android.support.test:runner:1.0.2。 打开文件 显示详细信息

无法解决“:app@debugAndroidTest/compileClasspath”的依赖关系:无法解决com.android.support.test.espresso:espresso-core:3.0.2。 打开文件 显示详细信息

无法解决“:app@debugAndroidTest/compileClasspath”的依赖关系:无法解决com.android.support:appcompat-v7:28.0.0-rc01。 打开文件 显示详细信息

无法解决“:app@debugAndroidTest/compileClasspath”的依赖关系:无法解决com.android.support.constraint:constraint-layout:1.1.2。 打开文件 显示详细信息

无法解决“:app@debugUnitTest/compileClasspath”的依赖关系:无法解决com.android.support:appcompat-v7:28.0.0-rc01。 打开文件 显示详细信息

无法解决“:app@debugUnitTest/compileClasspath”的依赖关系:无法解决com.android.support.constraint:constraint-layout:1.1.2。 打开文件 显示详细信息

无法解决“:app@release/compileClasspath”的依赖关系:无法解决com.android.support:appcompat-v7:28.0.0-rc01。 打开文件 显示详细信息

无法解决“:app@release/compileClasspath”的依赖关系:无法解决com.android.support.constraint:constraint-layout:1.1.2。 打开文件 显示详细信息

无法解决“:app@releaseUnitTest/compileClasspath”的依赖关系:无法解决com.android.support:appcompat-v7:28.0.0-rc01。 打开文件 显示详细信息

无法解决“:app@releaseUnitTest/compileClasspath”的依赖关系:无法解决com.android.support.constraint:constraint-layout:1.1.2。 打开文件 显示详细信息


1
请分享您的Gradle文件。而不是粘贴屏幕截图,请将堆栈跟踪粘贴在文本中。 - Abubakar
1
我建议使用androidx.appcompat:appcompat库代替com.android.support:appcompat-v7,因为支持库在28.0.0之后将不再获得更新。 - tyczj
更新了包含Gradle文件和日志的问题。 - user2454202
@tyczj 那并没有帮助。我仍然有这个问题,而且不仅仅是与appcompat有关的问题。以下所有元素都失败了implementation 'com.android.support:appcompat-v7:28.0.0-rc01' implementation 'com.android.support.constraint:constraint-layout:1.1.2' 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' - user2454202
15个回答

10

检查你的网络连接。对于我来说,这只是一个网络连接问题。如果你正在使用代理服务器,请转到 文件 > 设置 > 外观和行为 > 系统设置 > HTTP代理 并输入您的代理详细信息。使用"检查连接"选项验证您的连接。这里是我的gradle文件的参考。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
       applicationId "com.oops.pk.birthday_card"
       minSdkVersion 23
       targetSdkVersion 28
       versionCode 1
       versionName "1.0"
       testInstrumentationRunner 
       "android.support.test.runner.AndroidJUnitRunner"  
    }
    buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 
             'proguard-rules.pro'
          }
     }
}

dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
     implementation 'com.android.support:support-v4:28.0.0'
     implementation 'com.android.support:recyclerview-v7:28.0.0'
     implementation 'com.android.support:design:28.0.0'
     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'
 }

4

我在中国使用Shadowsocks代理,在打开~/.gradle/gradle.properties文件后,注释掉https主机和端口。

#systemProp.https.proxyPort=1080
systemProp.http.proxyHost=127.0.0.1
#systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080

之后,再次创建新项目或重新构建您的项目即可完成。

2
这种方法对我很有效。
进入- build.gradle(Module:app)
搜索(对我而言):
implementation 'com.android.support:appcompat-v7:29.+’
将其替换为:
implementation 'com.android.support:appcompat-v7:28.+'
点击“同步”或“重试”。
参考: 之前: 之后

2

我的同事也遇到了同样的问题。我们通过删除.android.AndroidStudiox.x.gradle文件夹来解决这个问题。这将删除所有当前的安卓设置,并在再次打开安卓工作室时重新下载。请确保安卓工作室已关闭。enter image description here


我试过了,这个可以用。谢谢@Vishal G. Gohel。 - Kinjal

1

使用:

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

.+将匹配任何版本的appcompat-v7:28。目前在Google's Maven存储库中有28.0.0-alpha1和28.0.0-alpha3


1

如果您已经勾选了离线模式,则需要禁用它。文件 > 设置 > 构建、执行和部署 > Gradle - 取消选中离线模式并应用。

另外,请检查您的互联网连接。


1

1
  1. 原因

    如果你在中国,可能是因为你的 Android Studio 没有正确设置代理。所以当你构建应用程序时,gradle 无法访问 Google 的 Maven 存储库 来下载依赖项(例如支持库)。

    请注意: Android Studio 允许使用 socks 代理和 http 代理,但 gradle 只允许使用 http 代理。因此,如果你在 Android Studio 中设置了 socks 代理,则可能会发现 Android Studio 可以下载 SDK 或甚至进行升级。但是当你构建时,gradle 无法下载支持库,因为你现在使用的是 socks 代理。

  2. 如何修复

    如果你使用 Shadowsocks 代理,请按照以下步骤操作:

    • 对于 Mac OS:

      你应该下载 ShadowsocksX-NG 而不是 ShadowsocksX,因为 ShadowsocksX 可能与 Android Studio 不兼容。 而 ShadowsocksX-NG 使用 socks5 代理,Android Studio 访问 socks5 代理,但请记住 gradle 不支持。

      你可以在“首选项设置”中查看 ShadowsocksX-NG 的代理信息,如下所示:

      • 本地 socks5 主机:127.0.0.1

      • 本地 socks5 端口:1086

      • 本地 PAC 端口:1089

      • 本地 http 端口:1087

      因此,你应该像这样在 Android Studio 中设置 http 代理:

      set http proxy in AS on Mac

    • 对于 Windows:

      你可以下载 Shadowsocks-windows 并查看正确的主机和端口,然后将它们设置为 Android Studio 代理。

      • 如果你选择了 http 代理,则可以设置如下:

        set http proxy in AS on Windows

        如果仍然无法工作,请尝试将以下代码添加到 ~/.gradle/gradle.properties 文件中:

        systemProp.https.proxyHost=127.0.0.1

        systemProp.https.proxyPort=1080

        systemProp.http.proxyHost=127.0.0.1

        systemProp.http.proxyPort=1080

      • 如果你选择了 socks 代理,则可以设置如下:

        set socks proxy in AS on Windows

        如果你使用 socks 代理,可能仍然无法工作,请尝试将以下代码添加到 ~/.gradle/gradle.properties 文件中,如下所示:

        set socks proxy for gradle

        这样做的目的是设置 gradle 代理。

    希望这能帮到你。


0
我遇到了同样的错误。我找到了解决方案。我希望它也能帮助你。
前往 build.gradle(Module:app)删除
 implementation 'com.android.support:design:28.0.0-rc01'

0

如果您有其他正常工作(无错误)的Android Studio项目,

您可以检查Project - app下的build.gradle设置,并查找此行:

implementation 'com.android.support:appcompat-v7:***'

你的工作SDK版本是否在你的工作项目中,然后替换你的

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

使用可工作的 SDK 版本 (***)

如果您没有任何可正常运行的项目,可以尝试使用我的:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'

希望这可以解决你的问题,因为它刚刚解决了我的问题。

我仍然有这个问题无法解决依赖项“:app@debug / compileClasspath”的问题:无法解决com.android.support:appcompat-v7:28.0.0-alpha3。 无法解决依赖项“:app@debug / compileClasspath”的问题:无法解决com.android.support.constraint:constraint-layout:1.1.2。 - user2454202

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接