赞
踩
记录了使用AndroidStudio2022.3 Giraffe版本在搭建环境时遇到的问题,包括连接超时,gradle无法读取等。
如果只看如何正确的配置,直接跳转第3节 配置汇总
项目一开始会自动下载gardle文件来加载项目
基本上很快就会连接超时
于是试了给项目的settings.gradle加上下载源,但是未生效
再次尝试修改模块的properties
配置文件来指定下载源
源地址:https://mirrors.cloud.tencent.com/gradle/gradle-8.0-bin.zip
顺利成功
但是下载gradle编译太过于依赖网络,于是尝试下载gradle到本地,再使用本地gradle
尝试使用本地下载的gradle遇到的问题
gradle默认下载目录在C:/Users/用户名/.gradle/wrapper/dists/
,我尝试了将gradle文件自行下载到该目录下,然后修改gradle-wrapper.properties
文件中关于下载的配置,重新Sync项目,但是报错Could not load wrapper properties from
这里为什么没有成功识别properties指定的本地目录的原因没找到,猜测可能是
gradles
文件夹作为下载位置,下载的gradle文件还要进一步放在/wrapper/dists
文件夹下Use Gradle From
为自己下载的gradle,注意需要解压,另外把Gradle JDK改为了本地jdk8版本。A problem occurred configuring root project ‘My Application3’.
Could not resolve all files for configuration ‘:classpath’.
Could not resolve com.android.tools.build:gradle:8.1.2.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:8.1.2
No matching variant of com.android.tools.build:gradle:8.1.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute ‘org.gradle.plugin.api-version’ with value ‘8.0’ but:
- Variant ‘apiElements’ capability com.android.tools.build:gradle:8.1.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn’t say anything about org.gradle.plugin.api-version (required ‘8.0’)
- Variant ‘javadocElements’ capability com.android.tools.build:gradle:8.1.2 declares a component for use during runtime, and its dependencies declared externally:
gradle plugins
和gradle
是两个东西,类似于maven插件
与maven仓库
Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
意思大概是gradle8.0版本应对应最低java11,而我设置使用本地java8
更改setting中JDK版本为AndroidStudio自行下载的jdk17
再次编译!成功
首先是连接超时关于下载镜像的更换
源地址:https://mirrors.cloud.tencent.com/gradle/gradle-8.0-bin.zip
不想下载镜像源,想使用本地gradle
下载gradle地址
在E盘下新建了如图的gradles
文件夹作为下载位置,下载的gradle文件还要进一步放在/wrapper/dists
文件夹下,
另外,AGP插件使用本地gradle如果需要下载一些东西又可能连接超时,所以在本地gradle文件中创建一个配置文件,指定下载源
init.gradle文件内容:
allprojects { repositories { mavenLocal() maven { name "Alibaba" ; url "https://maven.aliyun.com/repository/public" } maven { name "Bstek" ; url "https://nexus.bsdn.org/content/groups/public/" } mavenCentral() } buildscript { repositories { maven { name "Alibaba" ; url 'https://maven.aliyun.com/repository/public' } maven { name "Bstek" ; url 'https://nexus.bsdn.org/content/groups/public/' } maven { name "M2" ; url 'https://plugins.gradle.org/m2/' } } } }
本地gradle
时,要注意gradle plugins
版本,可以自行查询两者版本对应关系Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。