无法编译我的android项目

时间:2015-09-19 06:14:02

标签: android gradle android-recyclerview build.gradle android-appcompat

当我尝试编译我的android项目时,我收到以下错误。

  Error:A problem occurred configuring project ':app'.
  Could not resolve all dependencies for configuration ':app:_debugCompile'.
  Could not find com.android.support:appcompat-v7:21.0.1.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/support/appcompat-v7/21.0.1/appcompat-v7-21.0.1.pom
         https://jcenter.bintray.com/com/android/support/appcompat-v7/21.0.1/appcompat-v7-21.0.1.jar
         file:/home/baman/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/21.0.1/appcompat-v7-21.0.1.pom
         file:/home/baman/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/21.0.1/appcompat-v7-21.0.1.jar
         file:/home/baman/Android/Sdk/extras/google/m2repository/com/android/support/appcompat-v7/21.0.1/appcompat-v7-21.0.1.pom
         file:/home/baman/Android/Sdk/extras/google/m2repository/com/android/support/appcompat-v7/21.0.1/appcompat-v7-21.0.1.jar
     Required by:
         SriLankaTemples:app:unspecified
   Could not find com.android.support:recyclerview-v7:21.0.1.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/support/recyclerview-v7/21.0.1/recyclerview-v7-21.0.1.pom
         https://jcenter.bintray.com/com/android/support/recyclerview-v7/21.0.1/recyclerview-v7-21.0.1.jar
         file:/home/baman/Android/Sdk/extras/android/m2repository/com/android/support/recyclerview-v7/21.0.1/recyclerview-v7-21.0.1.pom
         file:/home/baman/Android/Sdk/extras/android/m2repository/com/android/support/recyclerview-v7/21.0.1/recyclerview-v7-21.0.1.jar
         file:/home/baman/Android/Sdk/extras/google/m2repository/com/android/support/recyclerview-v7/21.0.1/recyclerview-v7-21.0.1.pom
         file:/home/baman/Android/Sdk/extras/google/m2repository/com/android/support/recyclerview-v7/21.0.1/recyclerview-v7-21.0.1.jar
     Required by:
         SriLankaTemples:app:unspecified

这是我的Gradle文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "23.0.0 rc2"

    defaultConfig {
        applicationId "lk.lankahomes.baman.srilankatemples"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.1'
    compile 'com.android.support:recyclerview-v7:21.0.1'
}

有人可以帮我解决这个问题。

3 个答案:

答案 0 :(得分:7)

这是因为支持库的 21.0.1 不存在

您可以在build.gradle其中一个中使用:

dependencies{

  //it requires compileSdkVersion 23
  compile 'com.android.support:appcompat-v7:23.2.0'
  compile 'com.android.support:appcompat-v7:23.1.1'
  compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile 'com.android.support:appcompat-v7:23.0.0'

  //it requires compileSdkVersion 22
  compile 'com.android.support:appcompat-v7:22.2.1'
  compile 'com.android.support:appcompat-v7:22.2.0'
  compile 'com.android.support:appcompat-v7:22.1.1'
  compile 'com.android.support:appcompat-v7:22.1.0'
  compile 'com.android.support:appcompat-v7:22.0.0'

  //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'

}

同样的考虑也适用于com.android.support:recyclerview-v7

答案 1 :(得分:7)

我遇到了类似的问题并安装了android SDK构建工具-v23.0.1并引用了Android设置指南https://facebook.github.io/react-native/docs/android-setup.html#content

但无法找到“Android支持存储库”,对于最新版本的SDK管理器 - 该选项已更改为“支持库的本地maven存储库”。

enter image description here

答案 2 :(得分:1)

我认为buildToolsVersion "23.0.0 rc2"行导致了问题。

将其更改为buildToolsVersion "21.0.1"

或尝试

compileSdkVersion 21
buildToolsVersion "22.0.1"

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

并且是的,sharj所说的也是正确的,你可能错过了构建工具