Gradle build capaplities zeinab mohamed

22
Gradle Build Capabilities Presented By: Zeinab Mohamed AbdelMawla Software Engineer at OrangeLabs-Eg LinkedIn: https:// eg.linkedin.com/in/zeinabmohamed1 1

Transcript of Gradle build capaplities zeinab mohamed

Page 1: Gradle build capaplities zeinab mohamed

Gradle Build Capabilities

Presented By:

Zeinab Mohamed AbdelMawla

Software Engineer at OrangeLabs-Eg

LinkedIn: https://eg.linkedin.com/in/zeinabmohamed11

Page 2: Gradle build capaplities zeinab mohamed

Goals

2

• Why need Gradle ?• What Gradle Files ?• Adding dependencies • Automate Sign Configuration for apk• Configure Property. • Build diff build types and Product flavors• Merging Resources • Writing Your Own Custom Tasks• Testing• Performance Recommendations

Page 3: Gradle build capaplities zeinab mohamed

3

Page 4: Gradle build capaplities zeinab mohamed

Example

4

Page 5: Gradle build capaplities zeinab mohamed

AndroidBuild System

5

Page 6: Gradle build capaplities zeinab mohamed

6

Page 7: Gradle build capaplities zeinab mohamed

Gradle Files

7

Page 8: Gradle build capaplities zeinab mohamed

Adding Libraries :

8

• One of the biggest features in gradle build adding libraries.

will download library and it’s transitive libraries .

• We could disable transitive libraies for certin library :

Page 9: Gradle build capaplities zeinab mohamed

9

• You can also exclude a transitive dependency in the dependencies block

Page 10: Gradle build capaplities zeinab mohamed

Release Apk : • You need to digitally sign an APK so it can be released to the

Google Play store.

10

Page 11: Gradle build capaplities zeinab mohamed

Gradle Extendibility

11

• You need to automate changes of different build variantsAs ( debug - staging – release - ….)

Page 12: Gradle build capaplities zeinab mohamed

12

• Adding dependencies for different build types :

Page 13: Gradle build capaplities zeinab mohamed

13

• Product Flavors and Variants : You want to build essentially the same application, but with different resources and/or classes.

• You want to add Android activities or other Java classes to individual product flavors.

Page 14: Gradle build capaplities zeinab mohamed

14

• Each product flavor can have its own values of the following properties, among others, which are based defaultConfig:• applicationId• minSdkVersion• targetSdkVersion• versionCode• versionName• signingConfig

• Also Each flavor defines its own source set and resources :

main/java, you can also add source files in:• app/src/falvour1/java• app/src/falvour2/javaYou can also add additional resource files in:• app/src/falvour1/res• app/src/falvour2/res/layout

Page 15: Gradle build capaplities zeinab mohamed

• To see all the available variant names (build type + flavor ) , we add the custom task to your module build.

A custom task to print available variants

15

task printVariantNames() {doLast {android.applicationVari

ants.all { variant ->println variant.name}}}

> gradlew printVariantNames

Page 16: Gradle build capaplities zeinab mohamed

Merging Recourses

16

• Merging resources from different flavors and build types.

• If we want to change resources according to certain flavor.

• You want to add Android activities or other Java classes to individual product flavors.

Page 17: Gradle build capaplities zeinab mohamed

17

Page 18: Gradle build capaplities zeinab mohamed

Problem

You want to change the images, text, or other resources in a product flavor.

SolutionAdd the proper resource directories to your flavor, add the relevant files, and changethe values they contain.

18

Page 19: Gradle build capaplities zeinab mohamed

Writing Your Own Custom Tasks• Automate certain task and customize the Gradle build process with your own tasks

• Example :

Copy APKs to another folder

task copyApks(type: Copy) {from("$buildDir/outputs/apk") {exclude '**/*unsigned.apk', '**/*unaligned.apk'}into '../apks'}

NOTE : If you would like the copyApks task to run every time you do a build, make it adependency of the build task, build.dependsOn copyApks

.19

Page 20: Gradle build capaplities zeinab mohamed

• A custom task to print available variants

task printVariantNames() { doLast { android.applicationVariants.all { variant -> println variant.name } } }

20

Page 21: Gradle build capaplities zeinab mohamed

• Install all the debug flavors on a single device

task installDebugFlavors() {

android.applicationVariants.all { v -> if (v.name.endsWith('Debug')) { String name = v.name.capitalize() dependsOn "install$name" } } }

• Note

The applicationVariants property is only available for the com.android.applicationplug-in. A libraryVariants property is available in Android libraries. A testVariantsproperty is available in both.

21

Page 22: Gradle build capaplities zeinab mohamed

Using Android Libraries• If you want to use custom library to modularize your code

we can create module and include it to your project set .

Steps :

Add the module to your app dependencies

compile project(path: ':libtest‘)

Include the module to the project

include ': libtest ',

22