Playing with project’s build.gradle file

Updated 1 March 2017

Save

Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program. ~ (We know who have said that other wise no point of telling it. If you still don’t know follow this link)

 

It’s two months now that no blog come from my side. But sit back and relax, blog updates will now come every week to keep you updated and you can enjoy reading the blog while learning some handy tricks and tech.

Build.gradle file allows you to configure your project or module as per the project need.  Following are some handy options that will help you to take the benefits of it.

1. DEFINING SIGNING CONFIGURATION:

defining signing configuration allows creating different signing configuration used in the project. It can be used in running built variant in release mode or whenever there are different project flavors in the application.

 

For defining an external variable like MOBIKUL_HYERLOCAL_KEY use gradle.properties and access via project.MOBIKUL_HYERLOCAL_KEY. Follow EXTERNALIZING THE DEPENDENCY AND KEYWORD section for more

You can access the signing configuration inside buildTypes

2. EXTERNALIZING THE DEPENDENCY AND KEYWORDS:

Externalizing the keywords and dependency allows you to build the project on different dependency without having the pain to download and maintain it everywhere.

Thus, no conflict dependency issue that occurs in support libraries and play service libraries. Keywords can also be defined in the same manner.

gradle.properties

This is how this file will look:

 

3. CREATING ANDROID STRING AND JAVA CONSTANT AT BUILD TIME:

You can create all the constant (if you want)  in the build file. Moreover, You have control to change the constant depending upon the buildType and like that.

Please note while creating String resource you need to add extra quotes.

All the JAVA CONSTANT are defined in BuildConfig.java file generated at build time

 

You can access it easily from anywhere:

 

4. TAKING MORE CONTROL: CHANGING BASE PROPERTY like changing application name of the generated application as per your need:

You can use setProperty method to change the base name.

Here you application name will contain version name along with predefined string instead of app

 

That all folks.

STAY UPDATED…

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home