解决 MPAndroidChart 无法引入依赖的问题

前端之家收集整理的这篇文章主要介绍了解决 MPAndroidChart 无法引入依赖的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

刚刚犯了一个低级错误

引用 MPAndroidChart 这个开源的图表库的时候,按照官方的提示去引入依赖库,结果同步的时候,怎么都编译不过。

提示的信息就是:

Failed to resolve: com.github.PhilJay:MPAndroidChart:v3.0.2

可我记得自己明明就按照配置说明进行的配置的啊。

先看官方文档。

然后,再比较自己的配置文件

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. maven { url "https://jitpack.io" }
  5. }
  6. dependencies {
  7. classpath 'com.android.tools.build:gradle:2.2.0'
  8.  
  9. // NOTE: Do not place your application dependencies here; they belong
  10. // in the individual module build.gradle files
  11. }
  12. }
  13.  
  14. allprojects {
  15. repositories {
  16. jcenter()
  17.  
  18. }
  19. }
  20.  
  21. task clean(type: Delete) {
  22. delete rootProject.buildDir
  23. }
  24.  
  25. dependencies {
  26. compile fileTree(dir: 'libs',include: ['*.jar'])
  27. androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
  28. exclude group: 'com.android.support',module: 'support-annotations'
  29. })
  30. compile 'com.android.support:appcompat-v7:25.0.1'
  31. compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
  32. testCompile 'junit:junit:4.12'
  33. }

初看,没有什么问题。但就是编译不通过,百思不得其解。

但是后来看到 stackoverflow 上的答案时,才明白了错误所在。

我将

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

这一句错误地放置在了 buildscript{} 中,正确的应该是这样的。

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. }
  5. dependencies {
  6. classpath 'com.android.tools.build:gradle:2.2.0'
  7.  
  8. // NOTE: Do not place your application dependencies here; they belong
  9. // in the individual module build.gradle files
  10. }
  11. }
  12.  
  13. allprojects {
  14. repositories {
  15. jcenter()
  16. maven { url "https://jitpack.io" }
  17. }
  18. }
  19.  
  20. task clean(type: Delete) {
  21. delete rootProject.buildDir
  22. }

看来,写程序还是要细心为好,小小的一个失误有时候会让你怀疑人生。

参考

stackoverflow

猜你在找的设计模式相关文章