Android plugin

plugins android

Android Gradle plugin adds several features that are specific to building Android apps. To add plugin you must add repository and dependency in top-level buld.gradle file

buildscript {
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android Gradle plugin 3.0.0 or higher.
        google()
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

The on module level add plugin

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
// depricated
// apply plugin: 'kotlin-android-extensions'

After that, you can use the android block

Code example

Java 8

Java 8 has been supported natively since Android SDK 26.

Android Gradle plugin 4+ allows to use a number of Java 8 language APIs without requiring a minimum API level for your app ( full list):

  • java.util.stream
  • subset of java.time
  • java.util.function
  • recent additions to java.util.{Map,Collection,Comparator}
  • optionals (java.util.Optional, java.util.OptionalInt and java.util.OptionalDouble)
  • some additions to java.util.concurrent.atomic
  • ConcurrentHashMap (with bug fixes for Android 5.0)
Code example