Android Studio 编译加速

本文探讨了在Android Studio中优化编译过程的方法,包括开启离线模式、配置相关参数、调整Gradle设置等,以显著减少编译时间,从接近6分钟缩短至58秒。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用了1个多月的AS了,感觉比eclipse好的不是一点半点,但是就是有一点,编译一次太慢了,最长要接近6分钟,感觉真的是无法忍受了,所以放下手头上的事,找了一些资料,下面说一下。

1.在android studio的配置中,开启offline模式,
这里写图片描述
原因:offline work,看名字就知道是离线工作,因为gradle每次启动都会有联网检测依赖的各种文件是否是最新版本,导致每次都相当慢。如果确定了你的工程中的jar包或者依赖工程都齐全,也不想去更新最新的,就可以在gradle setting中勾选offline,这样就不会去更新了。

2.配置相关
这里写图片描述

3.修改项目下的gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
# TODO: disable daemon on CI, since builds should be clean and reliable on servers
org.gradle.daemon=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true

说明:
(1)org.gradle.daemon=true 开启gradle单独的守护进程
(2)org.gradle.configureondemand=true
(3)org.gradle.parallel=true 让gradle可以平行的运行
(4)org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 增大gradle运行的java虚拟机的大小

优化完这些测试:Rebuild project,时间从接近6分钟变为了58s,改善还是相当可观的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值