这是我的第一个使用Android Studio的项目,如果您发现这个问题是天真的,请不要理我。我想在我的Android Studio项目(版本0.8.1)中包含Cardslib库。最初我尝试通过在build.gradle中添加以下行来包含它:
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
但它返回了以下错误(同步时)
Error:Failed to find: com.github.gabrielemariotti.cards:library:1.7.3
我试图通过
包含jar文件编译文件(' libs / library-1.7.3-sources.jar')`
虽然gradle项目同步没有任何错误,但我无法创建简单的卡,但仍然无法为我工作。
我想要第一种方法,因为Android Studio可以处理所有内容,但我想我正在做一些可怕的错误。
[编辑] - 添加build.gradle代码
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
答案 0 :(得分:3)
在你的脚本中添加这个块,告诉gradle它可以在哪里找到libs的repo。
repositories {
mavenCentral()
}
所以你的脚本将是这样的:
.......
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}
.......