Gradle build capaplities zeinab mohamed
-
Upload
zeinab-mohamed-abdelmawla -
Category
Technology
-
view
101 -
download
4
Transcript of 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
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
3
Example
4
AndroidBuild System
5
6
Gradle Files
7
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 :
9
• You can also exclude a transitive dependency in the dependencies block
Release Apk : • You need to digitally sign an APK so it can be released to the
Google Play store.
10
Gradle Extendibility
11
• You need to automate changes of different build variantsAs ( debug - staging – release - ….)
12
• Adding dependencies for different build types :
•
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.
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
• 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
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.
17
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
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
• A custom task to print available variants
task printVariantNames() { doLast { android.applicationVariants.all { variant -> println variant.name } } }
20
• 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
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