【问题标题】:Failed to resolve: com.android.support:appcompat-v7:21.0.1无法解决:com.android.support:appcompat-v7:21.0.1
【发布时间】:2017-06-13 23:12:14
【问题描述】:

我最近将 mindSdkVersion 更改为 17,将 targetSdkVersion 更改为 21,并且出现了很多错误。我修复了其中一些,但我无法修复这个:

Error:(28, 13) Failed to resolve: com.android.support:appcompat-v7:21.0.1

我在 Mac 上使用 Android Studio,并且我有 Android 支持存储库。

我的 build.gradle 文件:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 21
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.swit.sedamaker"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 2
        versionName "1.01"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {

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

    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    testCompile 'junit:junit:4.12'
}

【问题讨论】:

    标签: android


    【解决方案1】:

    尝试替换为:

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

    【讨论】:

    • @AmirAmini,当然你想把targetSdkVersion 21 保持在 21,尝试升级到 23
    • 感谢它的工作,得到了其他错误,但我修复了它们。但现在我无法在模拟器上安装它。它说安装了我的应用程序的另一个版本,但这是我第一次在这个模拟器上运行我的应用程序。
    • @AmirAmini,如果有帮助,请考虑接受答案。清理你的项目。
    • 发现模拟器的存储空间已满。感谢您的帮助
    【解决方案2】:

    您最好匹配compileSdkVersionbuildToolsVersiontargetSdkVersion 的 API 版本。尝试使用最新的 SDK

    应用插件:'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.3"
        defaultConfig {
            ...
            minSdkVersion 17
            targetSdkVersion 24
            ...
        }
        ...
    }
    
    dependencies {
    
        compile 'com.android.support:appcompat-v7:24.2.0'
        ...
    }
    

    当然,如果需要,您可以将 targetSdkVersion 设置为 21。 targetSdkVersion 用于通知系统您已针对目标版本测试应用程序,如documentation 所说。

    android:targetSdkVersion

    一个整数,指定 API 级别, 应用目标。如果未设置,则默认值等于给定的值 到 minSdkVersion。此属性通知系统您拥有 针对目标版本进行了测试,系统不应启用任何 兼容性行为以保持您的应用程序的向前兼容性 与目标版本。该应用程序仍然能够在旧版本上运行 版本(低至 minSdkVersion)。

    更多信息请访问What is the difference between compileSdkVersion and targetSdkVersion?compileSdkVersiontargetSdkVersion

    【讨论】:

      【解决方案3】:

      出现错误是因为支持库的 21.0.1 不存在。

      dependencies{
      
      //it requires compileSdkVersion 21
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile 'com.android.support:appcompat-v7:21.0.2'
        compile 'com.android.support:appcompat-v7:21.0.0'
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-03
        • 2017-01-04
        • 2017-01-23
        • 2020-10-06
        • 2019-12-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多