I add gradle.properties file in my root project dir,and add this config:
org.gradle.jvmargs=-Xmx4096M
works. From the error message we can know the Daemon JVM spcace exhausted. This is the Gradle official docuemnt about this config:
Specifies the JVM arguments used for the Gradle Daemon. The setting is
particularly useful for configuring JVM memory settings for build
performance. This does not affect the JVM settings for the Gradle
client VM. The default is -Xmx512m “-XX:MaxMetaspaceSize=256m”.