11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android Studioのビルドを少し早く出来た

Last updated at Posted at 2016-06-22

背景

Android Studioのビルド時間を少し改善出来たので、メモ書き。

確認環境

  • プロジェクト
    • Multi-Dexしないとビルド出来ない位のソースコード量
  • PC
    • Macbook Air
      • CPU:Core i5 1.6GHz
      • RAM:8GB

Gradleについて

DexOptions

仕事だとあまりtoolやpluginのアップデートを積極的に行えなかったりする(のに甘えて)ものでそんなにAndroid Plugin DSL Referenceを見ていなかったのですが、DexOptionsを見たらこんなのが用意されてました。

要するに時間の掛かるdex compileを別プロセスで実行することでgreatな感じにパフォーマンスが良くなる、ってことと理解しました。まだ試験段階ってことらしいですが、今回はこちらを試してみました。

試した設定

dexInProcessを有効にしてあります。ビルドしているとXmx8192mに設定しなさいって怒られたので、gradle.propertiesの設定も合わせて設定してます。

{module}/build.gradle
dexOptions {
    javaMaxHeapSize "2g"
    dexInProcess true
}
{project_root}/build.gradle
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'
}
gradle.properties
org.gradle.jvmargs=-Xmx8192m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

試したtask

普段開発してるときに一番使ってるであろうflavorのdebug assembleで試しました。
1回目は少し時間かかるので、何回か実行してみて慣らしが効いた状態での効果を確認しました。

実行コマンド
gradlew clean assemble{Flavor}Debug

結果(と所感)

ビルドした結果今まで1分は確実に掛かっていたビルドが40秒程度まで早くなりました。
この辺りはjavaMaxHeapSizeやmaxProcessCountとか、そもそものPCスペックも影響すると思うので、探り探りで環境に合った設定をしてあげる必要がありそうです。

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?