gradle / build Flashcards
What is Gradle?
A build automation tool
What is the Manifest responsible for declaring? (4)
App’s package name (used by build tools and Google Play)
App’s components (Activities, Services, Broadcast Receivers, Intent filters etc)
Permissions
Hardware and software required (for device compatibility)
What is Manifest data used by?
Android OS, Android build tools, Google Play
What is AndroidX?
How is it enabled?
Jetpack libraries - they ship separately from the Android platform and replace the Support Library.
Enabled by setting 2 gradle.properties:
android.useAndroidX = true
(this uses androidX libraries instead of Support Libraries)
enableJetifier = true
(migrates existing third-party libraries to use AndroidX dependencies by rewriting their binaries)
What do the following properties define and where can they be found?
- compileSdkVersion
- targetSdkVersion
- minSdkVersion
Found in build.gradle(Module:app)
android{
compileSdkVersion // specifies the Android API Gradle should use to compile your app. Newest supported version.
targetSdkVersion // most recent API tested against - usually same as compileSdkVersion - may be different from compile version if app was developed to target an earlier version of Android
minSdkVersion // Oldest version of Android on which the app will run.
}
How are the 3 xml namespaces defined and what are their purposes?
xmlns:android=”http://schemas.android.com/apk/res/android”
Enables use of keys from core Android libraries (standard keys eg android:id, android:layoutHeight, etc)
xmlns:tools=”http://schemas.android.com/tools”
For use in previewing layouts in development
xmlns:app=”http://schemas.android.com/apk/res-auto”
For attributes originating from custom code or non-core Android libraries (includes constraintEnd_toEndOf etc). Can be useful for backwards compatibility using androidx.
What is the effect of setting the following?
- tools:context
- tools:layout
With what syntax should they be set?
tools:context=”fully.qualified.activity.name”
Enables the preview to display with the activity’s theme (stored in the manifest and thus otherwise unavailable until compile time)
tools:layout=”@layout/my_fragment_layout_xml”
Enables a fragment layout, for example, to be previewed on the specified main layout. Also useful in displaying layouts in nav_graphs.
What does Gradle do with vector drawables when building for API < 21?
Why?
Why might this be a problem?
Gradle auto-creates png files from vector drawables.
Vector drawables only supported from API21 onwards. This can be a problem as it increases app size.
How do you enable vector drawables on unsupported APIs ( < 21 ) ?
vectorDrawables.useSupportLibrary = true
( in build.gradle(Module:app) )
Replace android:src with app:srcCompat
What are the main differences between the following?
- build.gradle
- settings.gradle
- gradle.properties
build.gradle define dependencies, plugins and configurations for app module and other modules
settings.gradle
include all subprojects / components / features so gradle knows what’s included in the build
gradle.properties
k-v properties for things like enabling Jetpack, R8 etc
Where are constants stored for dependency versions?
In build.gradle(Project:)
ext{
version_navigation = “1.0.0” // (example)
}
What 2 things might DSL stand for?
Domain-Specific Language
Digital Subscriber Line
(formerly Digital Subscriber Loop)
DSL = a family of technologies that are used to transmit digital data over telephone lines.
Usually DSL = ADSL (Asymmetric DSL)
The asymmetric part of the tech (sending data down copper wires) means download speeds are greater than upload speeds.
What is the Application class?
How do you override it? (2)
Base class for maintaining global application state. The main object the OS uses to interact with your app.
Override by creating a subclass and specifying the fully-qualified name as the “android:name” attribute in your AndroidManifest.xml’s ^application^ tag.
What does APK stand for?
Android Package Kit
a package file format
You can put code in the application class if… (2)
The whole app will use it
It needs to be initialised once, before everything else is set up