Unknown host 'maven.google.com'

本文解决了一个常见的Android Studio编译错误——Unknown host ‘dl.google.com’。通过修改app/build.gradle文件中的URL从https://maven.google.com/更改为https://dl.google.com/dl/android/maven2,并更新Ubuntu系统的hosts文件,将dl.google.com指向IP地址203.208.40.36,成功解决了该问题。

这个问题没有能直接解决…

解决方案:

app/build.gradle 原代码:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        ...
    }
}
allprojects {

    repositories {
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

第一步:更改 url

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        maven {
            url 'https://dl.google.com/dl/android/maven2'
            name 'Google'
        }
    }

    dependencies {
        ...
    }
}
allprojects {

    repositories {
        maven {
            url 'https://dl.google.com/dl/android/maven2'
            name 'Google'
        }
    }
}

第二部,更改 hosts 文件 (Ubuntu 系统文件路径:/etc/hosts)
sudo gedit /etc/hosts
写入:203.208.40.36     dl.google.com
写入后的 hosts 文件:
在这里插入图片描述
重新编译,搞定!!!
附上参考博客:AndroidStudio编译时Unknown host ‘dl.google.com’. You may need to adjust the proxy settings

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/C:/Maven/apache-maven-3.9.11-bin/apache-maven-3.9.11/lib/guice-5.1.0-classes.jar) WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release [INFO] Scanning for projects... [INFO] Artifact org.springframework.boot:spring-boot-starter-parent:pom:3.5.4 is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from [nexus-cargo (http://maven.kgkj.com/repository/public/, default, releases+snapshots), github (https://maven.pkg.github.com/gcs-zhn/ddddocr-for-java, default, releases)] [INFO] Artifact org.springframework.boot:spring-boot-starter-parent:pom:3.5.4 is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from [nexus-cargo (http://maven.kgkj.com/repository/public/, default, releases+snapshots), github (https://maven.pkg.github.com/gcs-zhn/ddddocr-for-java, default, releases)] Downloading from nexus-cargo: http://maven.kgkj.com/repository/public/org/springframework/boot/spring-boot-starter-parent/3.5.4/spring-boot-starter-parent-3.5.4.pom [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for com.example:test1:0.0.1-SNAPSHOT: The following artifacts could not be resolved: org.springframework.boot:spring-boot-starter-parent:pom:3.5.4 (present, but unavailable): Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:3.5.4 from/to nexus-cargo (http://maven.kgkj.com/repository/public/): ��֪�������������� (maven.kgkj.com) and 'parent.relativePath' points at no local POM @ line 5, column 10 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.example:test1:0.0.1-SNAPSHOT (C:\Users\14028\IdeaProjects\test\test1\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for com.example:test1:0.0.1-SNAPSHOT: The following artifacts could not be resolved: org.springframework.boot:spring-boot-starter-parent:pom:3.5.4 (present, but unavailable): Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:3.5.4 from/to nexus-cargo (http://maven.kgkj.com/repository/public/): ��֪�������������� (maven.kgkj.com) and 'parent.relativePath' points at no local POM @ line 5, column 10: Unknown host ��֪�������������� (maven.kgkj.com) -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
08-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值