【问题标题】:Failed to resolve: com.android.support:appcompat-v7.27.+ [duplicate]无法解决:com.android.support:appcompat-v7.27.+ [重复]
【发布时间】:2018-11-26 03:49:28
【问题描述】:

我正在尝试使用 Nougat 7.0 在 Android Studio 中创建一个新项目。

但是,一旦我打开项目,我就会收到以下 Gradle 错误:

无法解决:com.android.support:appcompat-v7.27.+

我尝试了一些在线解决方案,但没有一个对我有用。

下面是模块(app)build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "damo.com.testproject"
    minSdkVersion 23
    targetSdkVersion 27
    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:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}

我需要进行哪些更改才能解决此问题?

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    buildToolsVersion "25.0.2" 将此更改为“27.0.0” 一切都会正确的

    【讨论】:

      【解决方案2】:

      找不到 Gradle DSL 方法:'google()'

      设置

      compileSdkVersion 27
      buildToolsVersion "27.0.3"
      

      确保在您的 PROJECT LEVEL build.gradle 部分添加 google()

      allprojects {
          repositories {
              google()
              jcenter()
              maven { url 'https://maven.google.com/' }
      
          }
      }
      

      如果设置PROPER版本会更好。

      compile 'com.android.support:appcompat-v7:27.1.1' 
      

      仅供参考

      使用 implementation 代替 compile。即

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

      之后,Clean-Rebuild-Run

      【讨论】:

        【解决方案3】:

        用这个替换

        com.android.support:support-compat:27.1.1

        【讨论】:

        • 嗨 @nishant 现在,当我尝试同步 gradle 时,我得到:Gradle DSL method not found: 'google()'
        • 转到您的项目级别 gradle 并将 google() 添加到所有项目依赖项
        • 抱歉,您不需要在所有项目存储库中添加依赖项
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 2018-01-03
        • 2017-01-04
        • 2017-01-23
        • 2017-06-13
        • 2020-10-06
        相关资源
        最近更新 更多