[已解决] android突然不能编译的问题

小豆苗 3月前 ⋅ 660 阅读

最近两天在编译android项目时,突然报引用库错误的问题,好多maven的引用库不可用。废话不多说,直接说解决办法:

Caused by: org.gradle.api.resources.ResourceException: Unable to load Maven meta-data from https://maven.google.com/com/android/support/support-v4/maven-metadata.xml

解决思路,用国内的镜像,替换之前的镜像地址

  1. 打开AndroidStudio的gradle的编译文件build.gradle
  2. buildscript {
        repositories {
            google()
            jcenter()
            
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.3'       
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
  3. 改为阿里云的镜像
    buildscript {
        repositories {
            jcenter{url 'https://maven.aliyun.com/repository/public'} // 阿里的镜像库,包含了mavencentral仓和jcenter仓
            google{url 'https://maven.aliyun.com/repository/google'}
            
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.3'
            
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter{url 'https://maven.aliyun.com/repository/public'}
            google{url 'https://maven.aliyun.com/repository/google'}
        }
    }​
  4. 可以正常编译通过,问题解决。

全部评论: 0

    我有话说: