提高AS編譯工程效率

復(fù)制官網(wǎng)的文章部分。記錄下


Improve build times by configuring DEX resources

When you deploy a clean build, Android Studio instruments your app to allow Instant Run to push code and resource updates. Although updating the running app happens much more quickly, the first build may take longer to complete. You can improve the build process by configuring a fewDexOptionssettings:

maxProcessCount

Sets the maximum number of DEX processes that can be started concurrently. If the Gradle daemon is already running, you need to stop the process before initializing it with a new maximum process count. You can terminate the Gradle daemon by calling one of the following from theTerminalwindow:

On Windows, callgradlew --stop

On Linux/Mac OSX, call./gradlew --stop

javaMaxHeapSize

Sets the maximum memory allocation pool size for the dex operation. When passing a value, you can append the letter 'k' to indicate kilobytes, 'm' to indicate megabytes, or 'g' to indicate gigabytes.

The following example setsmaxProcessCountto 4 andjavaMaxHeapSizeto "2g" in the module-levelbuild.gradlefile:

android{

...

dexOptions{

maxProcessCount4// this is the default value

javaMaxHeapSize"2g"

}

}

You should experiment with these settings by incrementing their values and observing the effect on your build times. You could experience a negative impact to performance if you allocate too many resources to the dexing process.

Enable dexing-in-process and incremental Java compilation

Android Plugin for Gradle version 2.1.0and higher features additional build process improvements, including incremental Java compilation and dexing-in-process. Incremental Java compilation is enabled by default and reduces compilation time during development by only recompiling portions of the source that have changed or need to be recompiled.

Dexing-in-process performs dexing within the build process rather than in a separate, external VM process. This not only makes incremental builds much faster, but also significantly speeds up full builds. To enable this feature, you need to set the Gradle daemon's maximum heap size to at least 2048 MB. You can do this by including the following in your project'sgradle.propertiesfile:

org.gradle.jvmargs=-Xmx2048m

If you have defined a value forjavaMaxHeapSizein your module-levelbuild.gradlefile, you need to set the daemon's max heap size to the value ofjavaMaxHeapSize+ 1024 MB. For example, if you have setjavaMaxHeapSizeto "2g", you need to add the following to your project'sgradle.propertiesfile:

org.gradle.jvmargs=-Xmx3072m

Exclude your project from Windows Defender

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末墓捻,一起剝皮案震驚了整個濱河市焰望,隨后出現(xiàn)的幾起案子鹿寻,更是在濱河造成了極大的恐慌届谈,老刑警劉巖,帶你破解...
    沈念sama閱讀 210,914評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件斩启,死亡現(xiàn)場離奇詭異饰迹,居然都是意外死亡芳誓,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,935評論 2 383
  • 文/潘曉璐 我一進店門啊鸭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來锹淌,“玉大人,你說我怎么就攤上這事赠制÷赴冢” “怎么了?”我有些...
    開封第一講書人閱讀 156,531評論 0 345
  • 文/不壞的土叔 我叫張陵钟些,是天一觀的道長烟号。 經(jīng)常有香客問我,道長政恍,這世上最難降的妖魔是什么汪拥? 我笑而不...
    開封第一講書人閱讀 56,309評論 1 282
  • 正文 為了忘掉前任,我火速辦了婚禮篙耗,結(jié)果婚禮上迫筑,老公的妹妹穿的比我還像新娘。我一直安慰自己鹤树,他們只是感情好铣焊,可當(dāng)我...
    茶點故事閱讀 65,381評論 5 384
  • 文/花漫 我一把揭開白布逊朽。 她就那樣靜靜地躺著罕伯,像睡著了一般。 火紅的嫁衣襯著肌膚如雪叽讳。 梳的紋絲不亂的頭發(fā)上追他,一...
    開封第一講書人閱讀 49,730評論 1 289
  • 那天坟募,我揣著相機與錄音,去河邊找鬼邑狸。 笑死懈糯,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的单雾。 我是一名探鬼主播赚哗,決...
    沈念sama閱讀 38,882評論 3 404
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼硅堆!你這毒婦竟也來了屿储?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,643評論 0 266
  • 序言:老撾萬榮一對情侶失蹤渐逃,失蹤者是張志新(化名)和其女友劉穎够掠,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體茄菊,經(jīng)...
    沈念sama閱讀 44,095評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡疯潭,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,448評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了面殖。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片竖哩。...
    茶點故事閱讀 38,566評論 1 339
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖脊僚,靈堂內(nèi)的尸體忽然破棺而出期丰,到底是詐尸還是另有隱情,我是刑警寧澤吃挑,帶...
    沈念sama閱讀 34,253評論 4 328
  • 正文 年R本政府宣布钝荡,位于F島的核電站,受9級特大地震影響舶衬,放射性物質(zhì)發(fā)生泄漏埠通。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,829評論 3 312
  • 文/蒙蒙 一逛犹、第九天 我趴在偏房一處隱蔽的房頂上張望端辱。 院中可真熱鬧,春花似錦虽画、人聲如沸舞蔽。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,715評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽渗柿。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間朵栖,已是汗流浹背颊亮。 一陣腳步聲響...
    開封第一講書人閱讀 31,945評論 1 264
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留陨溅,地道東北人终惑。 一個月前我還...
    沈念sama閱讀 46,248評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像门扇,于是被迫代替她去往敵國和親雹有。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,440評論 2 348

推薦閱讀更多精彩內(nèi)容