【问题标题】:Could not resolve com.android.support:appcompat-v7:28.0.0无法解析 com.android.support:appcompat-v7:28.0.0
【发布时间】:2018-12-20 07:29:20
【问题描述】:

关于这个有很多不同的问题,但是关于使用v7.28.0v7.28.+v7.28.0.0-rc02的问题但是当我同步我的项目时,我得到了这个错误:

无法解析 ':app@debug/compileClasspath' 的依赖关系:可以 无法解析 com.android.support:appcompat-v7:28.0.0。

我检查了Support library setup 并按照它的说明进行操作,但没有帮助。

这是我的模块应用程序

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.mobaleghan.nasimnoor"
        manifestPlaceholders = [
                onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 8
        versionName "1.6.3"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation "com.android.support:support-core-utils:28.0.0"
    implementation 'com.onesignal:OneSignal:3.10.3'
}

和项目等级:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

我已经在设置中测试过,android studio 的互联网连接很好,但我不知道该去哪里找。

我什至在 AS 3.2.1 中创建了一个新项目,但我得到了同样的错误。 不知道为什么this happens every time I update AS

【问题讨论】:

  • 你试过用VPN编译吗?
  • @SiSa 我想我不知道你在说什么!
  • 您是否尝试将support:support-annotations 更新为28.0.0?
  • @AlexJolig 你知道对伊朗有一些制裁。一些谷歌功能也遵循这些制裁。因此,为了下载库并成功编译,您需要在 VPN/代理运行时进行编译
  • @SiSa 是的!那!是的,我正在使用 VPN

标签: android android-studio android-gradle-plugin


【解决方案1】:

我确信其他答案很好并且有效。但我的通过将代理设置为Freedom of Developers 解决了。

此解决方案适用于像我这样受到谷歌对伊朗人严格限制的波斯人。

现在我的应用 gradle 看起来像这样:

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.mobaleghan.nasimnoor"
        manifestPlaceholders = [
                onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 9
        versionName "1.6.4"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.android.support:support-core-utils:28.0.0"
    implementation 'com.onesignal:OneSignal:3.10.3'
}

这些存储库基于OneSignal documentations

以及顶级构建:

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

一切正常。

【讨论】:

    【解决方案2】:

    Android 项目有 2 个 gradle 文件:一个存储在项目范围内,一个存储在应用程序范围内。 (请注意,一个项目内部可以有许多应用程序,但您通常只有一个)。所以你只需要在这 2 个 gradle 文件中交换定义的存储库 url。

    第 1 步:删除您的 build.gradle(应用程序)中的这些代码行

    repositories {
        maven { url 'https://maven.google.com' }
    }
    

    第 2 步:将此添加到您的 build.gradle(项目)

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

    您必须知道28.0.0android.support 的最后一个稳定版本。因此,您可能希望降级版本或将所有内容迁移到androidX

    28.0.0 的稳定版本将是打包为 android.support 的最终功能版本。所有后续功能版本都将仅作为 androidx 打包的工件提供。

    查看link,欢迎来到androidX 的新时代。

    【讨论】:

      【解决方案3】:

      尝试以下方法:

      1) 从构建工具中取消选中离线工作: 文件->其他设置->默认设置->构建、执行、部署->构建工具->Gradle->取消勾选离线工作选项。

      2) 如果上述方法不起作用,请转到您项目的构建 gradle 并在存储库下添加以下内容:

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

      【讨论】:

      • Offile 工作已经被取消选中,第二种方法没有帮助。正如我所说,我已经检查了其他问题中的所有解决方案,并且我链接的文档说它适用于较旧的 gradle 版本
      【解决方案4】:

      将此部分从模块的build.gradle 合并到根项目的build.gradle

      buildscript {
          repositories {
              maven { url 'https://plugins.gradle.org/m2/'}
          }
          dependencies {
              classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
          }
      }
      
      repositories {
          maven { url 'https://maven.google.com' }
      }
      

      仅将这些行保留在模块的build.gradle:

      apply plugin: 'com.android.application'
      apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
      
      android {
         ...
      }
      

      根项目的build.gradle 应该看起来像这样:

      buildscript {
          repositories {
              google()
              jcenter()
              maven { url 'https://plugins.gradle.org/m2/' }
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:3.2.1'
              classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
          }
      }
      
      allprojects {
          repositories {
              google()
              jcenter()
          }
      }
      

      【讨论】:

      • 谢谢。但我不知道为什么这些解决方案都不起作用!
      【解决方案5】:

      您仍然可以使用 28.0.0 版本,但似乎是时候迁移到 Android X了!

      根据Support Library Documentation

      注意:随着 Android 9.0(API 级别 28)的发布,有一个新的 称为 AndroidX 的支持库版本,它是 喷气背包。 AndroidX 库包含现有的支持库 并且还包括最新的 Jetpack 组件。

      您可以继续使用支持库。历史文物 (那些版本为 27 及更早版本,并打包为 android.support.*) 将在 Google Maven 上保持可用。但是,所有新图书馆 开发将在 AndroidX 库中进行。

      我们建议在所有新项目中使用 AndroidX 库。你 还应该考虑将现有项目也迁移到 AndroidX。

      【讨论】:

        猜你喜欢
        • 2021-02-26
        • 2020-05-12
        • 2019-04-05
        • 1970-01-01
        • 2015-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多