虛擬機怎麼提高編譯速度
A. 如何優化 Android Studio 啟動,編譯和運行速度
優化 Android Studio 啟動、編譯和運行速度?
【阿里雲】攜手碼雲為社區用戶送福利,全網專享,詳情請點擊>>> »
作為一名 Android 程序員,選擇一個好的 IDE 工具可以使開發變得非常高效,很多程序員喜歡使用 Google 的 Android Studio來進行開發,但使用起來有時會出現卡頓等問題。本文介紹了幾種優化 Android Studio 啟動、編譯、運行速度的方法。
首先解決一個 Android Studio 啟動報錯的問題
1、進入剛安裝的 Android Studio 目錄下的bin目錄。找到 idea.properties 文件,用文本編輯器打開。
2、在 idea.properties 文件末尾添加一行:disable.android.first.run=true,然後保存文件。
3、關閉 Android Studio 後重新啟動,便可進入界面。
優化 Android Studio 啟動速度
1、開啟 gradle 單獨的守護進程
當 Android Studio 遇到錯誤的時候,往往會導致 Android Studio 掛掉,為了防止推出程序,則另外開啟一個線程來守護 Android Studio 的進程,具體操作。 在 C:\Users\.gradle 這個目錄下,創建 gradle.properties 配置文件,復制以下配置進行優化。
# Project-wide Gradle settings.
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
這些配置文件主要就是增大 gradle 運行的 java 虛擬機的大小,讓 gradle 在編譯的時候使用獨立進程,讓 gradle 可以很好的運行。
2、擴大內存
64位:\studio64.exe.vmoptions or studio.exe.vmoptions
32位:\studio.exe.vmoptions or studio.exe.vmoptions
編輯這個文件,在最開始的兩行設置內存大小,類似於eclipse.ini中的配置。配置如下:
-Xms256m
-Xmx1024m
B. Android Studio編譯慢,卡死和狂佔內存怎麼破
你好,已經使用Android Studio進行開發超過一年,隨著項目的增大,依賴庫的增多,構建速度越來越慢,現在最慢要6分鍾才能build一個release的安裝包,在網上查找資料,發現可以通過一些配置可以加快速度,這里跟大家分享一下。
開啟gradle單獨的守護進程
在下面的目錄下面創建gradle.properties文件:
/home/<username>/.gradle/ (linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)
並在文件中增加:
org.gradle.daemon=true
同時修改項目下的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
同時上面的這些參數也可以配置到前面的用戶目錄下的gradle.properties文件里,那樣就不是針對一個項目生效,而是針對所有項目生效。上面的配置文件主要就是做, 增大gradle運行的java虛擬機的大小,讓gradle在編譯的時候使用獨立進程,讓gradle可以平行的運行。
修改android studio配置區 在android studio的配置中,開啟offline模式,以及修改配置。實際上的配置和上面的一大段一樣,主要是在這個地方配置的只會在ide構建的時候生效,命令行構建不會生效。
C. ssd 能提升linux虛擬機的編譯速度么
差不多吧,其實都差不多。。。虛擬機的性能損失,肯定有的,主要還不是在硬碟,SSD 可能會快一些,其實虛擬機主要性能在CPU 和內存,最好買個支持虛擬化的CPU
D. 如何加快Android Studio的編譯速度
針對編譯慢的問題,網上找了一些解決方案:
看看我android studio上配置gradle:
E. java 編譯優化問題
java編譯的結果是位元組碼而不是二進制,所以在運行時vm的優化才是重要的,包括VM的回收策略、分配給VM內存的大小都能在一定程度上影響性能。Sun的VM支持熱點編譯,對高頻執行的代碼段翻譯的2進制會進行緩存,這也是VM的一種優化。
IBM JVM處理數學運算速度最快,BEA JVM處理大量線程和網路socket性能最好,而Sun JVM處理通常的商業邏輯性能最好。不過Hotspot的Server mode被報告有穩定性的問題。
Java 的最大優勢不是體現在執行速度上,所以對Compiler的要求並不如c++那樣高,代碼級的優化還需要程序員本身的功底。
貼個java的運行參數:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print proct version and exit
-version:<value>
require the specified version to run
-showversion print proct version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see
java.lang.instrument
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs rece use of OS signals by Java/VM (see
documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.
Java虛擬機(JVM)參數配置說明
在Java、J2EE大型應用中,JVM非標准參數的配置直接關繫到整個系統的性能。
JVM非標准參數指的是JVM底層的一些配置參數,這些參數在一般開發中默認即可,不需
要任何配置。但是在生產環境中,為了提高性能,往往需要調整這些參數,以求系統達
到最佳新能。
另外這些參數的配置也是影響系統穩定性的一個重要因素,相信大多數Java開發人員都
見過「OutOfMemory」類型的錯誤。呵呵,這其中很可能就是JVM參數配置不當或者就沒
有配置沒意識到配置引起的。
為了說明這些參數,還需要說說JDK中的命令行工具一些知識做鋪墊。
首先看如何獲取這些命令配置信息說明:
假設你是windows平台,你安裝了J2SDK,那麼現在你從cmd控制台窗口進入J2SDK安裝目
錄下的bin目錄,然後運行java命令,出現如下結果,這些就是包括java.exe工具的和
JVM的所有命令都在裡面。
-----------------------------------------------------------------------
D:\j2sdk15\bin>java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print proct version and exit
-version:<value>
require the specified version to run
-showversion print proct version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see
java.lang.instrument
-----------------------------------------------------------------------
在控制台輸出信息中,有個-X(注意是大寫)的命令,這個正是查看JVM配置參數的命
令。
其次,用java -X 命令查看JVM的配置說明:
運行後如下結果,這些就是配置JVM參數的秘密武器,這些信息都是英文的,為了方便
閱讀,我根據自己的理解翻譯成中文了(不準確的地方還請各位博友斧正)
-----------------------------------------------------------------------
D:\j2sdk15\bin>java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs rece use of OS signals by Java/VM (see
documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.
The -X options are non-standard and subject to change without notice.
-----------------------------------------------------------------------
JVM配置參數中文說明:
-----------------------------------------------------------------------
1、-Xmixed mixed mode execution (default)
混合模式執行
2、-Xint interpreted mode execution only
解釋模式執行
3、-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
設置zip/jar資源或者類(.class文件)存放目錄路徑
3、-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
追加zip/jar資源或者類(.class文件)存放目錄路徑
4、-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
預先載入zip/jar資源或者類(.class文件)存放目錄路徑
5、-Xnoclassgc disable class garbage collection
關閉類垃圾回收功能
6、-Xincgc enable incremental garbage collection
開啟類的垃圾回收功能
7、-Xloggc:<file> log GC status to a file with time stamps
記錄垃圾回日誌到一個文件。
8、-Xbatch disable background compilation
關閉後台編譯
9、-Xms<size> set initial Java heap size
設置JVM初始化堆內存大小
10、-Xmx<size> set maximum Java heap size
設置JVM最大的堆內存大小
11、-Xss<size> set java thread stack size
設置JVM棧內存大小
12、-Xprof output cpu profiling data
輸入CPU概要表數據
13、-Xfuture enable strictest checks, anticipating future default
執行嚴格的代碼檢查,預測可能出現的情況
14、-Xrs rece use of OS signals by Java/VM (see
documentation)
通過JVM還原操作系統信號
15、-Xcheck:jni perform additional checks for JNI functions
對JNI函數執行檢查
16、-Xshare:off do not attempt to use shared class data
盡可能不去使用共享類的數據
17、-Xshare:auto use shared class data if possible (default)
盡可能的使用共享類的數據
18、-Xshare:on require using shared class data, otherwise fail.
盡可能的使用共享類的數據,否則運行失敗
The -X options are non-standard and subject to change without notice.
F. ssd 能提高linux虛擬機的編譯速度么
下載JDK for linux以jdk-6u24-linux-i586.bin
移動jdk-6u24-linux-i586.bin到/usr/java/
1、給許可權:sudo chmod u+x /usr/java/jdk-6u24-linux-i586.bin
2、安裝jdk:sudo /usr/java/jdk-6u24-linux-i586.bin
3、設置環境變數:
G. Java 虛擬機一樣的速度甚至出現AOT編譯方式嗎
不論是物理機還是虛擬機,大部分的程序代碼從開始編譯到最終轉化成物理機的目標代碼或虛擬機能執行的指令集之前,都會按照如下圖所示的各個步驟進行:
H. java編譯為什麼那麼慢
ecplipse編譯慢,並不是說編譯的工具慢,是由於工程代碼很多,導致內存短時間產生不夠的現象,表現出來的就是很慢。
很多程序在進行大數據的計算或者資料庫的操作,都需要很多的內存來計算或者保存數據,編譯環境這時候就會很卡。
I. 自己可以編譯安卓源碼嗎
用最新的Ubuntu 16.04,請首先確保自己已經安裝了Git.沒安裝的同學可以通過以下命令進行安裝:
sudo apt-get install git git config –global user.email 「[email protected]」 git config –global user.name 「test」
其中[email protected]為你自己的郵箱.
簡要說明
android源碼編譯的四個流程:1.源碼下載;2.構建編譯環境;3.編譯源碼;4運行.下文也將按照該流程講述.
源碼下載
由於某牆的原因,這里我們採用國內的鏡像源進行下載.
目前,可用的鏡像源一般是科大和清華的,具體使用差不多,這里我選擇清華大學鏡像進行說明.(參考:科大源,清華源)
repo工具下載及安裝
通過執行以下命令實現repo工具的下載和安裝
mkdir ~/binPATH=~/bin:$PATHcurl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repochmod a+x ~/bin/repo
補充說明
這里,我來簡單的介紹下repo工具,我們知道AOSP項目由不同的子項目組成,為了方便進行管理,Google採用Git對AOSP項目進行多倉庫管理.在聊repo工具之前,我先帶你來聊聊多倉庫項目:
我們有個非常龐大的項目Pre,該項目由很多個子項目R1,R2,...Rn等組成,為了方便管理和協同開發,我們為每個子項目創立自己的倉庫,整個項目的結構如下:
這里寫圖片描述
執行完該命令後,再使用make命令繼續編譯.某些情況下,當你執行jack-admin kill-server時可能提示你命令不存在,此時去你去out/host/linux-x86/bin/目錄下會發現不存在jack-admin文件.如果我是你,我就會重新repo sync下,然後從頭來過.
錯誤三:使用emulator時,虛擬機停在黑屏界面,點擊無任何響應.此時,可能是kerner內核問題,解決方法如下:
執行如下命令:
通過使用kernel-qemu-armv7內核 解決模擬器等待黑屏問題.而-partition-size 1024 則是解決警告: system partion siez adjusted to match image file (163 MB >66 MB)
如果你一開始編譯的版本是aosp_arm-eng,使用上述命令仍然不能解決等待黑屏問題時,不妨編譯aosp_arm64-eng試試.
結束吧
到現在為止,你已經了解了整個android編譯的流程.除此之外,我也簡單的說明android源碼的多倉庫管理機制.下面,不妨自己動手嘗試一下.