我有一个问题,Gradle无法找到我的依赖项(Android支持库)。
我的build.gradle看起来像这样:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/FlurryAgent.jar')
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
当我构建(在命令行上,没有IDE)时,我收到以下消息:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'AndroidCalculator'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':compile'.
> Could not find com.google.android:support-v4:r7.
Required by:
:AndroidCalculator:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
为什么我不允许像这样添加Android支持库?
答案 0 :(得分:16)
您已声明存储库依赖,但尚未声明存储库。因此无法解决依赖性。 (buildscript
块中的存储库/依赖项与主构建脚本中的存储库/依赖项严格分开。)
答案 1 :(得分:8)
此贴纸是AndroidAnnotations,Dagger,Jackson和Robolectric的精心设计的项目。
你需要的只是添加
repositories {
mavenCentral()
}
替换
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
with(上面链接的代码的第44行)
compile 'com.android.support:support-v4:18.0.+'
陷阱:只有在全新安装的情况下,最后一位才适用于Android Studio 0.2+。由于0.2 Studio附带其内部m2 repo以提供支持和google api库,因此如果您从以前的版本升级,则SDK不具备它。
还要确保local.properties文件存在于根文件夹中,而sdk.dir指向SDK
答案 2 :(得分:2)
您需要在dependency
代码中添加其他dependencies
。如果android-support-v4.jar
文件夹中有libs
库,请尝试添加下面列出的代码:
dependencies {
compile files('libs/android-support-v4.jar')
}