在Android Studio中解决Gradle依赖问题?

8

我正在尝试添加一个来自https://android-arsenal.com/details/1/1375的样式化进度条。

网站上写道:

将特定的存储库添加到您的构建文件中:

repositories {
   maven {
      url "https://jitpack.io"
   }
}

在你的构建文件中添加依赖项(不要忘记指定正确的限定符,通常为 'aar'):
dependencies {
   compile 'com.github.akexorcist:Android-RoundCornerProgressBar:1.0.0'
}

好的,我做到了… build.gradle(项目)

buildscript {
repositories {
    jcenter()
    maven {
      url "https://jitpack.io"
   }

}
  dependencies {
    classpath 'com.android.tools.build:gradle:1.1.0'

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

allprojects {
  repositories {
    jcenter()
  }
}

build.gradle (模块): 应用插件: 'com.android.application'

android { 编译SDK版本 21 构建工具版本 "21.1.2"

defaultConfig {
    applicationId "com.example.chaz.simsirl"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:21.0.3'
   compile 'com.github.akexorcist:Android-RoundCornerProgressBar:1.0.0'
}

然后在消息中显示:

错误:配置项目“:app”时出现问题。

无法解决配置“:app:_debugCompile”的所有依赖项。 找不到com.akexorcist:Android-RoundCornerProgressBar:1.0.0。 在以下位置中搜索: https://jcenter.bintray.com/com/akexorcist/Android-RoundCornerProgressBar/1.0.0/Android-RoundCornerProgressBar-1.0.0.pom      https://jcenter.bintray.com/com/akexorcist/Android-RoundCornerProgressBar/1.0.0/Android-RoundCornerProgressBar-1.0.0.jar     file:/C:/Users/pc/AppData/Local/Android/sdk/extras/android/m2repository/com/akexorcist/Android-RoundCornerProgressBar/1.0.0/Android-RoundCornerProgressBar-1.0.0.pom     file:/C:/Users/pc/AppData/Local/Android/sdk/extras/android/m2repository/com/akexorcist/Android-RoundCornerProgressBar/1.0.0/Android-RoundCornerProgressBar-1.0.0.jar     file:/C:/Users/pc/AppData/Local/Android/sdk/extras/google/m2repository/com/akexorcist/Android-RoundCornerProgressBar/1.0.0/Android-RoundCornerProgressBar-1.0.0.pom     file:/C:/Users/pc/AppData/Local/Android/sdk/extras/google/m2repository/com/akexorcist/Android-RoundCornerProgressBar/1.0.0/Android-RoundCornerProgressBar-1.0.0.jar 所需的:     SimsIRL:app:未指定


2
你把jitpack存储库放错了位置。它应该在allprojects下面。 - Andrejs
2个回答

28

您需要在不同的位置添加jitpack存储库:

allprojects {
  repositories {
    jcenter()
    maven { url "https://jitpack.io" }
  }
}

那么就可以工作了

在您的第一个片段中,它是在buildscript下添加的,应该从那里移除。


非常有帮助!谢谢。 - Trevor

0

嘿,谢谢!运行得很好。我现在感觉有点傻,没有早点注意到这个。 - pxlcrisis
4
这仅适用于@pxlcrisis,因为他们正在引用一个库,该库同时也有jCenter条目。Jitpack的目的是巧妙地允许gradle文件引用GitHub存储库,这是一种非常有用的方法,可以轻松编译自己的GitHub库分支。metrimer的答案应该被接受(在我看来),因为它解决了OP实际遇到的问题,即gradle没有搜索jitpack存储库。 - Trevor

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