[Android Learning] Android studio environment construction-solve the problem of slow downloading of gradle & slow loading of mainfest.xml

Reprint: https://blog.csdn.net/qq_31881469/article/details/78646406/

Table of contents

1. Solve network connection problems

(1) Problem description 

(2) Method steps 

2. Solve the problem of tight memory 

(1) Problem description 

(2) Method steps 

3. Solve the problem of slow build speed 

(1) Problem description 

(2) Method 


 

1. Solve network connection problems

Write picture description here

(1) Problem description 

        Check your Android SDK. If it is stuck for a long time, if it needs to be updated, you need to install it.

(2) Method steps 

①Skip this step, you can find the idea.properties file in the bin directory under the Android Studio installation directory, and append disable.android.first.run=true at the end of the file . 

# Use ${idea.home.path} macro to specify location relative to IDE installation home.
# Use ${xxx} where xxx is any Java property (including defined in previous lines of this file) to refer to its value.
# Note for Windows users: please make sure you're using forward slashes: C:/dir1/dir2.

#---------------------------------------------------------------------
# Uncomment this option if you want to customize a path to the settings directory.
#---------------------------------------------------------------------
# idea.config.path=${user.home}/.AndroidStudio/config

#---------------------------------------------------------------------
# Uncomment this option if you want to customize a path to the caches directory.
#---------------------------------------------------------------------
# idea.system.path=${user.home}/.AndroidStudio/system

#---------------------------------------------------------------------
# Uncomment this option if you want to customize a path to the user-installed plugins directory.
#---------------------------------------------------------------------
# idea.plugins.path=${idea.config.path}/plugins

#---------------------------------------------------------------------
# Uncomment this option if you want to customize a path to the logs directory.
#---------------------------------------------------------------------
# idea.log.path=${idea.system.path}/log

#---------------------------------------------------------------------
# Maximum file size (in KiB) IDE should provide code assistance for.
# The larger file is the slower its editor works and higher overall system memory requirements are
# if code assistance is enabled. Remove this property or set to very large number if you need
# code assistance for any files available regardless of their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=2500

#---------------------------------------------------------------------
# Maximum file size (in KiB) the IDE is able to open.
#---------------------------------------------------------------------
idea.max.content.load.filesize=20000

#---------------------------------------------------------------------
# This option controls console cyclic buffer: keeps the console output size not higher than the specified buffer size (KiB).
# Older lines are deleted. In order to disable cycle buffer use idea.cycle.buffer.size=disabled
#---------------------------------------------------------------------
idea.cycle.buffer.size=1024

#---------------------------------------------------------------------
# Configure if a special launcher should be used when running processes from within IDE.
# Using Launcher enables "soft exit" and "thread dump" features
#---------------------------------------------------------------------
idea.no.launcher=false

#---------------------------------------------------------------------
# To avoid too long classpath
#---------------------------------------------------------------------
idea.dynamic.classpath=false

#---------------------------------------------------------------------
# Uncomment this property to prevent IDE from throwing ProcessCanceledException when user activity
# detected. This option is only useful for plugin developers, while debugging PSI related activities
# performed in background error analysis thread.
# DO NOT UNCOMMENT THIS UNLESS YOU'RE DEBUGGING IDE ITSELF. Significant slowdowns and lockups will happen otherwise.
#---------------------------------------------------------------------
#idea.ProcessCanceledException=disabled

#---------------------------------------------------------------------
# There are two possible values of idea.popup.weight property: "heavy" and "medium".
# If you have WM configured as "Focus follows mouse with Auto Raise" then you have to
# set this property to "medium". It prevents problems with popup menus on some
# configurations.
#---------------------------------------------------------------------
idea.popup.weight=heavy

#---------------------------------------------------------------------
# Removing this property may lead to editor performance degradation under Windows.
#---------------------------------------------------------------------
sun.java2d.d3d=false

#---------------------------------------------------------------------
# Removing this property may lead to editor performance degradation on Java 8+.
#---------------------------------------------------------------------
swing.bufferPerWindow=true

#---------------------------------------------------------------------
# Removing this property may lead to editor performance degradation under X Window.
#---------------------------------------------------------------------
sun.java2d.pmoffscreen=false

#---------------------------------------------------------------------
# Enables HiDPI support in JBR
#---------------------------------------------------------------------
sun.java2d.uiScale.enabled=true

#---------------------------------------------------------------------
# Applicable to the Swing text components displaying HTML (except JEditorPane).
# Rebases CSS size map depending on the component's font size to let relative
# font size values (smaller, larger) scale properly. JBR-only.
#---------------------------------------------------------------------
javax.swing.rebaseCssSizeMap=true


#---------------------------------------------------------------------
# Workaround for accessing (in terms of a11y) long VCS logs on macOS. JBR-only.
#---------------------------------------------------------------------
sun.awt.mac.a11y.tableAccessibleRowCountThreshold=1000

#---------------------------------------------------------------------
# Enabling an optimization that excludes traversal of collapsed accessible nodes from the accessible tree. JBR-4167
#---------------------------------------------------------------------
javax.swing.JTree.excludeAccessibleChildrenFromClosedNodes=true

#---------------------------------------------------------------------
# Workaround to avoid long hangs while accessing clipboard under Mac OS X.
#---------------------------------------------------------------------
#ide.mac.useNativeClipboard=True

#---------------------------------------------------------------------
# Maximum size (KiB) the IDE will use to show historical file contents -
# in Show Diff or when calculating Digest Diff
#---------------------------------------------------------------------
#idea.max.vcs.loaded.size.kb=20480

#---------------------------------------------------------------------
# IDEA file chooser peeks inside directories to detect whether they contain a valid project
# (to mark such directories with a corresponding icon).
# Uncommenting the option prevents this behavior outside the user home directory.
#---------------------------------------------------------------------
#idea.chooser.lookup.for.project.dirs=false

#---------------------------------------------------------------------
# Experimental options that do a number of things to make truly smooth scrolling possible:
#
# * Enables hardware-accelerated scrolling.
#     Blit-acceleration copies as much of the rendered area as possible and then repaints only newly exposed region.
#     This helps to improve scrolling performance and to reduce CPU usage (especially if drawing is compute-intensive).
#
# * Enables "true double buffering".
#     True double buffering is needed to eliminate tearing on blit-accelerated scrolling and to restore
#     frame buffer content without the usual repainting, even when the EDT is blocked.
#
# * Adds "idea.true.smooth.scrolling.debug" option.
#     Checks whether blit-accelerated scrolling is feasible, and if so, checks whether true double buffering is available.
#
# * Enables handling of high-precision mouse wheel events.
#     Although Java 7 introduced MouseWheelEven.getPreciseWheelRotation() method, JScrollPane doesn't use it so far.
#     Depends on the Editor / General / Smooth Scrolling setting, remote desktop detection and power save mode state.
#     Ideally, we need to patch the runtime (on Windows, Linux and macOS) to improve handling of the fine-grained input data.
#     This feature can be toggled via "idea.true.smooth.scrolling.high.precision" option.
#
# * Enables handling of pixel-perfect scrolling events.
#     Currently, this mode is available only under macOS with JetBrains Runtime.
#     This feature can be toggled via "idea.true.smooth.scrolling.pixel.perfect" option.
#
# * Enables interpolation of scrolling input (scrollbar, mouse wheel, touchpad, keys, etc).
#     Smooths input, which lacks both spatial and temporal resolution, performs the rendering asynchronously.
#     Depends on the Editor / General / Smooth Scrolling setting, remote desktop detection and power save mode state.
#     The feature can be tweaked using the following options:
#       "idea.true.smooth.scrolling.interpolation" - the main switch
#       "idea.true.smooth.scrolling.interpolation.scrollbar" - scrollbar interpolation
#       "idea.true.smooth.scrolling.interpolation.scrollbar.delay" - initial delay for scrollbar interpolation (ms)
#       "idea.true.smooth.scrolling.interpolation.mouse.wheel" - mouse wheel / touchpad interpolation
#       "idea.true.smooth.scrolling.interpolation.mouse.wheel.delay.min" - minimum initial delay for mouse wheel interpolation (ms)
#       "idea.true.smooth.scrolling.interpolation.mouse.wheel.delay.max" - maximum initial delay for mouse wheel interpolation (ms)
#       "idea.true.smooth.scrolling.interpolation.precision.touchpad" - touchpad interpolation
#       "idea.true.smooth.scrolling.interpolation.precision.touchpad.delay" - initial delay for touchpad interpolation (ms)
#       "idea.true.smooth.scrolling.interpolation.other" - interpolation of other input sources
#       "idea.true.smooth.scrolling.interpolation.other.delay" - initial delay for other input source interpolation (ms)
#
# * Adds on-demand horizontal scrollbar in editor.
#     The horizontal scrollbar is shown only when it's actually needed for currently visible content.
#     This helps to save editor space and to prevent occasional horizontal "jitter" on vertical touchpad scrolling.
#     This feature can be toggled via "idea.true.smooth.scrolling.dynamic.scrollbars" option.
#---------------------------------------------------------------------
#idea.true.smooth.scrolling=true

#---------------------------------------------------------------------
# The VM option value to be used to start a JVM in debug mode.
# Some JREs define it in a different way (-XXdebug in Oracle VM)
#---------------------------------------------------------------------
idea.xdebug.key=-Xdebug

#-----------------------------------------------------------------------
# Change to 'enabled' if you want to receive instant visual notifications
# about fatal errors that happen to an IDE or plugins installed.
#-----------------------------------------------------------------------
idea.fatal.error.notification=disabled

disable.android.first.run=true

②Or: Use an off-wall proxy.

2. Solve the problem of tight memory 

(1) Problem description 

The -xmx parameter         in the Android Studio installation directory is a parameter used when starting the Java virtual machine and is used to limit the maximum heap memory . This parameter is set when Android Studio starts, and the default value is small. Once your project becomes larger and the IDE runs for a longer time, the memory will start to be tight, and GC will be triggered frequently, which will naturally cause it to get stuck.

(2) Method steps 

        After each upgrade/installation of Android Studio, modify the following attributes of the two files  android-studio/bin/studio64.exe.vmoptions studio64.vmoptions :

-Xms2048m 
-Xmx2048m 
-XX:MaxPermSize=2048m 
-XX:ReservedCodeCacheSize=2048m

-XX:+IgnoreUnrecognizedVMOptions
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
-XX:CICompilerCount=2
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-ea
-Dsun.io.useCanonCaches=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-Djdk.attach.allowAttachSelf=true
-Djdk.module.illegalAccess.silent=true
-Djna.nosys=true
-Djna.boot.library.path=
-Didea.vendor.name=Google
-Dkotlinx.coroutines.debug=off

3. Solve the problem of slow build speed 

(1) Problem description 

        As the project grows and the number of dependent libraries increases, the build speed becomes slower and slower. Now it takes at least 6 minutes to build a release installation package.

(2) Method 

        Enable a separate daemon process for gradle, increase the size of the Java virtual machine that gradle runs on, and let gradle use an independent process when compiling so that gradle can run in parallel.


①Create the gradle.properties file in the following directory : C:\Users\.gradle (Windows)

②Add in the file: org.gradle.daemon=true

③Optimize the gradle.properties file in the above user directory and configure it as follows:

# 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

 

Guess you like

Origin blog.csdn.net/qq_45769063/article/details/130858469