Gradle is a groovy-based language developed by google, a configuration language used to replace ant.
Gradle is an Android compilation system based on groovy language implementation (JVM-based syntax and java-like scripting language). The groovy language has developed a set of dsl, and there is an additional need to use groovy directly to solve
the gradle wrapper
. Each gradle-based project has a gradle local proxy, called gradle wrapper, which is
declared in the /gradle/wrapper/gralde-wrapper.properties directory to point to Directory and
version Create the file gradle.properties locally or create the gradle.properties file in the user's .gradle directory as a global setting, the parameters are
# Enable parallel compilation org.gradle.parallel=true # start the daemon org.gradle.daemon=true # compile on demand org.gradle.configureondemand=true # Set the compile jvm parameters org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # set proxy systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyPort=10384 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=10384 # Enable JNI compilation to support outdated APIs android.useDeprecatedNdk=true
Install a global gradle and configure the Path variable to avoid repeated downloads for each project, so that you can directly run the
common commands of gradle build after compiling the project.
Note: You can run gradlew directly under window. If it is Linux or mac, the command is gradle gradlew is abbreviated as ./gradle
mission command
# View all tasks ./gradlew tasks --all # run on a task [TaskName] of a module [moduleName] ./gradlew :moduleName:taskName
quick build command
# View build version ./gradlew -v # clear build folder ./gradlew clean # Check dependencies and compile and package ./gradlew build # Compile and install the debug package ./gradlew installDebug # compile and print log ./gradlew build --info # debug mode build and print log ./gradlew build --info --debug --stacktrace # Force update latest dependencies, clean build and build ./gradlew clean --refresh-dependencies build
Note that the build command prints out the packages of the debug and release environments.
If you need to specify the build, use the following command:
Specify the build target command
# Compile and print the Debug package ./gradlew assembleDebug ./gradlew aD # Compile and release the package ./gradlew assembleRelease ./gradlew aR
build and install debug commands
# Compile and print the Debug package ./gradlew assembleDebug # Compile the app module and hit the Debug package ./gradlew install app:assembleDebug # Compile and release the package ./gradlew assembleRelease # Release mode package and install ./gradlew installRelease # Uninstall the Release mode package ./gradlew uninstallRelease
assemble can also be used in combination with productFlavors. If there is an error like Task 'install' is ambiguous in root project, please check the multiple channels configured and modify the command to
./gradlew install[productFlavorsName] app:assembleDebug
to build and debug with the command
View package dependencies
./gradlew dependencies --info
View detailed dependency information
Use offline mode
./gradlew aDR --offline
daemon
./gradle build --daemon
Parallel compilation mode
./gradle build --parallel --parallel-threads=N
compile-on-demand mode
./gradle build --configure-on-demand
Do not use snapshot dependency warehouse
provided that it can be used offline
./gradlew clean aDR
Multi-channel packaging
assemble can also be used in combination with productFlavors
# Release mode package and install ./gradlew installRelease # Uninstall the Release mode package ./gradlew uninstallRelease
Warehouse settings
Set the central warehouse
The default is jcenter, can be mavenCentral
repositories { maven { url "http://maven.oschina.net/content/groups/public" } }
Android Studio speed up
Disable plugins
Remove some useless plugins
Google Cloud Testing, Google Cloud Tools For Android Studio, Google Login, Google Services, JavaFX, SDK Updater, TestNG-J
android studio 2.2.2 new features Compile cache
Project root directory gradle. properties file add
android.enableBuildCache=true
This setting allows Android Studio to cache the dependent jar or arr locally and set the module name to the hash value
quote
After this is enabled, the includeJarFilter configuration may be invalid, and Android Studio is upgraded to 2.3.0 to fix this problem
The cache generated by each compilation is in $HOME/.android/build-cache.
If there is too much cache, you can manually delete the directory to
clear it. Compilation incompatibility after
upgrading to Android Studio 2.3 After upgrading to Android Studio 2.3, Gradle Plugin is also upgraded to 2.3 .0
corresponds to the recommended Gradle version is 3.3.
At this time, you will find that the {module name}/build/intermediates/exploded-aar/
directory in the project module directory is missing, and
it will generate a part of the cache under $HOME/.android/build-cache file instead of exploded-aar
If you need to generate exploded-aar, you can configure gradle.properties in the project directory and add a line of content
android.enableBuildCache=false
Then rebuild the project to see the exploded-aar directory in {module name}/build/intermediates/