Android Studio Build running 时间过长且失败Gradle
Posted 哈特谢普苏特
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Studio Build running 时间过长且失败Gradle相关的知识,希望对你有一定的参考价值。
错误内容
Unable to resolve dependency for ':app:Infolibrary@debugandroidTest/compileClasspath':
Could not resolve androidx.core:core-ktx:1.3.0.
...
1.androidx build 失败
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.annotation:annotation:1.0.2'
2.其它 包括如下的可以直接注释
// testImplementation 'junit:junit:4.12'
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
- 重点解决1中的问题,查看日志C:\\Users\\78189\\.gradle\\daemon
- 查看日志发现错误是由于网络连接和锁导致的(其实就是国内外网络环境)
- 2021-05-05T16:03:34.839+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface WAN Miniport (L2TP)
2021-05-05T16:03:34.841+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2021-05-05T16:03:34.842+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface Microsoft Kernel Debug Network Adapter
2021-05-05T16:03:34.844+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2021-05-05T16:03:34.845+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface WAN Miniport (PPPOE)
2021-05-05T16:03:34.848+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2021-05-05T16:03:34.848+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface Microsoft Wi-Fi Direct Virtual Adapter
2021-05-05T16:03:34.851+0800 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
- 解决方法:(一个思路)
- 1.首先将所有的源换成国内的,比如阿里或其它(解决了部分问题)
- 2.使用代理(我这种情况代理也不行,stackoverflow说是因为地理位置原因,换了美国的代理还是不行)
- 3.降AS版本,以及所需要的库的版本(成功解决所有问题,包括2中的test)所有问题迎刃而解!!!!
- 原AS 4.0以上 gradle版本 4.1.3;6.5...
- 修改后
-
buildscript { ext.kotlin_version = '1.3.50' repositories { maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/public' } // google() // jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.5.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/public' } // google() // jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
只要思想不滑坡,办法总比困难多,下个问题见!!
以上是关于Android Studio Build running 时间过长且失败Gradle的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio开发Android——build.gradle文件详解
Android Studio 中build.gradle文件的详细解析
如何在Android Studio里设置Build Tool版本