剛剛犯了一個低級錯誤。
引用 MPAndroidChart 這個開源的圖表庫的時候,按照官方的提示去引入依賴庫,結果同步的時候,怎麼都編譯不過。
提示的資訊就是:
Failed to resolve: com.github.PhilJay:MPAndroidChart:v3.0.2
可我記得自己明明就按照配置說明進行的配置的啊。
先看官方文檔。
然後,再比較自己的配置檔案。
buildscript {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
testCompile 'junit:junit:4.12'
}
複制
初看,沒有什麼問題。但就是編譯不通過,百思不得其解。
但是後來看到 stackoverflow 上的答案時,才明白了錯誤所在。
我将
maven { url "https://jitpack.io" }
複制
這一句錯誤地放置在了 buildscript{} 中,正确的應該是這樣的。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
複制
看來,寫程式還是要細心為好,小小的一個失誤有時候會讓你懷疑人生。
參考
stackoverflow