Using Gradle in Android development.

Gradle is the official build system supported by Google for Android. It is written in Groovy programming language.

The Gradle build system for Android supports resource shrinking at build time. This automatically removes resources that are unused from the packaged application.In addition to removing resources in your project that are not actually needed at runtime, this also removes resources from libraries you are depending on if they are not actually needed by your application. This can hugely reduce the size of your application.

To enable resource shrinking, update your build file

android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
}
}

Providing different resources for the flavors

In order to define a different behavior for a certain flavor, you need to create suitable folders for the defined flavors under app/src/.
Flavor specific resources override the main resources, i.e., if you provide a different application icon in a flavor the Android build system picks up the flavor specific one if you are deploying or building your flavor.
1. The Gradle build system is designed to support complex scenarios in creating Android applications:

⁃ Multi-distribution: the same application must be customized for several clients or companies

⁃ Multi-apk: supporting the creation of multiple apk for different device types while reusing parts of the code

2. Gradle is an advanced build toolkit that manages dependencies and allows you to define custom build logic.

⁃ Android Studio uses a Gradle wrapper to fully integrate the Android plugin for Gradle.

⁃ The Android plugin for Gradle also runs independent of Android Studio. This means that you can build your Android apps from within Android Studio and from the command line on your machine or on machines where Android Studio is not installed (such as continuous integration servers).

3. Gradle is another build system that takes the best features from other build systems and combines them into one.

⁃ It is improved based off of their shortcomings. It is a JVM based build system, what that means is that you can write your own script in Java, which Android Studio makes use of.

4. One best thing about gradle is that it is a plugin based system.

– This means if you have your own programming language and you want to automate the task of building some package (output like a JAR for Java) from sources then you can write a complete plugin in Java or Groovy, and distribute it to rest of world.

5. Integration with Android Studio

– With Gradle, IDE integration isn’t an afterthought. Android Studio is deeply integrated with the new Gradle-based Android build system.

6. Simple, Declarative, Domain-specific Language

– Gradle Inc. worked together with Google to create a simple, declarative DSL(Domain Specific Language) for Android builds.

7. A Single Build System

– Gradle is the authoritative build across the IDE and the command-line. This means that the same build that powers Android Studio will power your command-line and continuous-integration builds.

8. Product Flavors, Build Variants, and Build Type

– Many mobile applications have a free version and a paid version while other applications may ship seasonal variations. With Gradle product flavors are easy to manage with a few lines of code. Build types control application packaging and build configuration for different types of debug and release builds.

9. Android Signing Configuration

– The Gradle Android DSL provides a very simple way to customize keystores and signing configuration across different build types.

10. Dependency Management

– Gradle offers a flexible approach to dependency management that can reuse existing Maven repositories or reference local JARs. If you depend on libraries from Cntral or if you run your own local repositories, Gradle can adapt to any requirement.

11. Multi-project Support

– Gradle supports multi-project builds from both the IDE and the command-line. With Gradle you can easily create builds that span multiple application and library projects.

12. Binary Bundles for Libaries (.aar)

– Gradle supports the new .aar binary bundle format for library projects.

13. Full Incremental Builds

– The new Gradle-based Android build system has been designed for developer efficiency. Gradle’s support for incremental tasks means you spend less time waiting and more time coding.

14. A Focus on Testing

– The Gradle-based Android build system bring a new focus on testing. With Gradle you can run unit and integration tests without creating sub projects. Gradle supports several scenarios for integration testing on build servers.

15. Test Server API supports Hosted Testing

– Integration with Jenkins-based build servers and services from AppThwack, TestDroid, and Manymo means that your build can support complex, massively-parallel integration testing scenarios.

Advantages of Gradle:

⁃ Configure and intercept all build phases of your project with the use of plugins
⁃ Dependency management
⁃ Distribution management
⁃ SCM integration.
⁃ Well integrated with Continuous Integration environments such as Jenkins.
⁃ The possibility to write your build script with a functional programming language.
⁃ Possibility to write your own tasks in Groovy (tasks are based on task Ant model).
⁃ POM generation.
⁃ Reuse of all Maven repositories.
⁃ Integration with Ivy repositories.
⁃ Polyglot build system to integrate projects with different technologies and programming languages.
⁃ Create multiple APKs for your app with different features using the same project.(create several variants of an application)
⁃ Reuse code and resources.
⁃ Customise, configure, and extend the build process.
⁃ Customised integration with their own IDE Android Studio.
⁃ Single build tools to support multiple languages.

Reference Links:

1. To support complex scenarios in Android applications: Stack overflow – What is gradle in android studio?
2. Advantages of Gradle: Quora – What are the advantages and disadvantages of gradle versus maven?
3. Features and Benefits: Gradle – The new gradle android build system.

Until Next Time…..

Android Team,
Mallow Technologies.

Leave a Reply

%d bloggers like this: