Table of Contents
Motivation
Understanding Gradle is mandatory if you want to build good Android apps
Bare Minimum
This is the bare minimum you need to be able to compile and run an Android application:
plugins { id 'com.android.application' id 'kotlin-android' } android { compileSdk 30 defaultConfig { applicationId "de.creatronix.myapplication" minSdk 21 } } dependencies { implementation 'androidx.core:core-ktx:1.6.0' }
Let’s dissect the parts
Plugins
Plugins are programs which extend the gradle build process
When you need special feature like annotation processing the Plugin goes here
Android
In this section you define for which specific android version you are developing:
minSdk means that your app isn’t supported on devices with an API level below.
targetSdk is the preferred Android version you like to run on
You can add buildTypes section to distinguish between release and debug builds.
In the release build you can e.g. enable the minification
How to enable R8 in your build process
How to fix android.view.InflateException: Error inflating class fragment
Depencencies
Dependencies come in many flavors:
implementation
These are dependencies which are needed to run the application
Until gradle 7.0 these dependencies were called “compile”. Now they are deprecated, so use implementation
testImplementation
The dependency is only available in the test source set.
androidTestImplementation
The dependency is only available in the androidTest source set.