markdown [Android studio / Gradle性能提示] #android

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown [Android studio / Gradle性能提示] #android相关的知识,希望对你有一定的参考价值。

#### Gradle tweaks

Open or create a file called gradle.properties in `.gradle` directory. Inside the file, add following
- `org.gradle.parallel=true`: Allow you to build multiple modules in the same project at the same time
- `org.gradle.daemon=true` will turn on daemon so that every time we build the application, it doesn’t need to rerun the entire Gradle application every time.

#### Memory Allocation tweaks

By default, Android Studio detects your installed RAM and configure the memory allocation automatically. However, the default value usually is too small to handle Android Studio. We can override it by opening it inside the Android Studio. **Click Help > Edit Custom VM Options**.

There are 4 config values you need to change:

- `-Xms1G`: Specifying the initial size of the memory allocation pool for JVM. For PC with 8GB of RAM, start specifying with -Xms1G is a sweet spot.

- `-Xms2G`: Specifying the maximum size of the memory allocation pool for JVM. For PC with 8GB of RAM, -Xmx2G is a good value to start.

- `-XX:MaxPermSize=1G`: Specifying the permanent generation. This allocated memory holds compiled class pages. If it’s already full, then it triggers a full garbage collection to clean the old unreferenced classes. I would say start with -XX:MaxPermSize=1G for a PC with 8GB of RAM. Some people said it’s not necessary anymore in Java 8, but I do still configure it anyway.

- `-XX:ReservedCodeCacheSize=512m`: Specifying the reserved code cache size. I don’t really understand what this config affects. But, still configure it anyway. In a PC with 8GB of RAM we can start with -XX:ReservedCodeCacheSize=512m.

#### Build gradle with profile report
`./gradlew android:assembleDebug --profile`

`--profile` flag will tell gradle to measure the time taken to execute each task and dump that data into HTML file. You can find that report under /projectDir/build/reports/profile directory.

以上是关于markdown [Android studio / Gradle性能提示] #android的主要内容,如果未能解决你的问题,请参考以下文章

markdown 加速Android Studio的终极指南

markdown Android Studio修改包名

markdown Android Studio动态调试Smali代码

markdown 更改Android Studio的“项目”面板字体

markdown 在没有Android Studio的情况下运行Android Emulator

markdown 在Android Studio模拟器中调试Chrome