看一下 google 關於 gradle 的文件, 使用 android-studio 創建立一個 gradle project,
測試了一下 dependencies, 一直出現以下錯誤. 實在搞不懂為什麼.
* What went wrong:
A problem occurred configuring project ':Test'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':Test:compile'.
> Could not find com.github.kevinsawicki:http-request:5.4.
Required by:
TestProject:Test:unspecified
後來總算 Google 到了, 才發現自己文件真是沒有看仔細.
在 buildscript 裡面的 mavenCentral 只是單純給 buildscript 裡面的 dependencies 使用,
如果要實際參照到自己的 dependencies 的話, 則要額外再補上 repositories.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
}
}
apply plugin: 'android'
/* 這個不加上去, dependencies 就會找不到 */
repositories {
mavenCentral()
}
dependencies {
/* compile files('libs/android-support-v4.jar') */
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.kevinsawicki:http-request:5.4'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
}
參照上面的 build.gradle, 這樣就可以了.
之後大概會把自己所有的 projects 全部轉成 gradle projects 吧.
更新:
不知道在那一版本的 android-studio, 下面這行已經會自動加上去了.
repositories {
mavenCentral()
}