What is Gradle file in android studio?

In Android Studio, Gradle is employed for building our android application projects, hence playing the role of a build system. Before Android Studio, in Eclipse we wont to compile and build the applications using instruction tool which was soon appropriated by GUI based steps to create and run Android Applications in eclipse using ANT. Every android application development tool has got to compile resources, java ASCII text file , external libraries and mix them into a final APK.

What is gradle?

Gradle may be a build system, which is liable for code compilation, testing, deployment and conversion of the code into .dex files and hence running the app on the device.

As Android Studio comes with Gradle system pre-installed, there’s no got to install additional runtime softwares to create our project. Whenever you click the Run button in Android Studio, the gradle task will automatically start and build the project starts, and after gradle completes its task, the application will run in
A build system like Gradle isn’t a compiler, linker etc, but it controls and supervises the operation of compilation, linking of files, running test cases, and eventually bundling the code into an apk file for your Android Application.

There are two build.gradle files for each android studio project of which, one is for application and other is for project level(module level) build files.

In the build process, the compiler takes the ASCII text file , resources, external libraries JAR files and AndroidManifest.xml(which contains the meta-data about the application) and convert them into .dex(Dalvik Executable files) files, which incorporates bytecode. That bytecode is supported by all android devices to run your app. Then APK Manager combines the .dex files and every one other resources into single apk file. APK Packager signs debug or release apk using respective debug or release keystore.

Debug apk is usually used for testing purpose or we will say that it’s used at development stage only. When your app is complete with desired features and you’re able to publish your application for external use then you need a Release apk signed employing a release keystore.

Let’s now shed some light on the rating files.

setting.gradle The setting.gradle(Gradle setting) file is employed to specify all the modules utilized in your app.

build.gradle (project level) the highest level (module) build.gradle file is project level build file, which defines build configurations at project level. This file applies configurations to all or any the modules in android application project.

build.gradle (application level) the appliance level build.gradle file is found in each module of the android project. This file includes your package name as applicationID, version name(apk version), version code, minimum and target sdk for a selected application module. once you are including external libraries(not the jar files) then you would like to say it within the app level gradle file to incorporate them in your project as dependencies of the appliance .

Note. If a specific application is developed in variations for individual modules, such as a smartphone, tablet or TV, then separate Gradle files must be created for all.. you’ll even start your gradle system through instruction tool. Following commands are used for it:

./gradlew build – (build project)
./gradlew clean build – (build project complete scratch)
./gradlew clean build – (run the test)
./gradlew wrapper – (all the available tasks)