What is Gradle ?
Gradle History & Why need Gradle ?
What is Gradle Files and project structure ?
Android Build System & the build graphe .
Build diff build types
Product flavors.
Merging Resources.
Adding dependencies.
Automate Sign Configuration for apk.
APK split.
Writing Your Own Custom Tasks.
Performance Recommendations.
What is new in Gradle?
2. Goals
- What is Gradle ?
- Gradle History & Why need Gradle ?
- Android Build System & the build graphe .
- Build diff build types
- Product flavors.
- Merging Resources.
- Adding dependencies.
- Automate Sign Configuration for apk.
- APK split.
- Writing Your Own Custom Tasks.
- Performance Recommendations.
- What is new in Gradle?
3. Gradle
- Gradle is a general-purpose build tool
Gradle is an open-source build automation tool that is designed to be
flexible enough to build almost any type of software based in Groovy.
4. Gradle History.
Idea come from :
For years, builds had the simple requirements of compiling and packaging
software.
But the modern software development has changed, and so have the needs
for build automation.
Today, projects involve large and diverse software stacks,
apply abroad of testing strategies. With the rise of agile practices, builds
must support early integration of code as well as frequent and easy delivery
to both test and production environments.
5. Gradle
- The core model is based on tasks
Any build process modeled as a graph of tasks , which is
one of the reasons why Gradle is so flexible. And that
task graph can be defined by both plugins and your
own build scripts, with tasks linked together via the
task dependency mechanism.
9. Gradle Capabilities >> Build types & Flavours
You need to automate changes of different build variants As ( debug - staging – release - ....)
10. Gradle Capabilities >> Product Flavours
Product Flavors and Variants : You want to build essentially the same
application, but with different resources and/or classes.
EX: You want to add Android activities or other Java classes to individual
product flavors.
12. Gradle Capabilities >> Product Flavours
Each product flavor can have its own values of the following properties,
among others, which are based defaultConfig:
- applicationId
- minSdkVersion
- targetSdkVersion
- versionCode
- versionName
- signingConfig
13. Gradle Capabilities >> Product Flavours
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/java
You can also add additional resource files in:
- app/src/falvour1/res
- app/src/falvour2/res/layout
14. Gradle Capabilities >> Merging resources
- 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.
15. Gradle Capabilities >> Adding dependencies
One of the biggest features in gradle build adding libraries.
main/java, you can also add source files in:
16. Gradle Capabilities >> Adding dependencies
will download library and it’s transitive libraries by default
We could disable transitive libraries for certain library :
17. Gradle Capabilities >> Adding dependencies
You can also exclude a transitive dependency in the
dependencies block.
18. Gradle Capabilities >> Automate APK Signing
You need to digitally sign an APK so it can be released to the Google Play store.
19. Gradle Capabilities >> APK Split
Although you should build a single APK to support all your target devices whenever possible, that might result in a very
large APK , one of the ways to reduce apk size is split based in certain conditions .
We can split vs :
Abi , density , language
We can also group some of tragests together
.
20. Gradle Capabilities >> APK Split
Also we can order to generate beside “universalAPk” with all combinations together
21. Gradle Capabilities >> Write Custom Task
Copy Apks to another folder to automate this process
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 a dependency of the build task,
build.dependsOn copyApks
Haaaay =D
Please feel free to write your Q through this link >> Q&A button
Ask a question at goo.gl/slides/7jf9bc
It’s used for almost any software not just android
And big privilege that can run anywhere just download gradle and their need tools like JDK for java .then >> build using command lines without
IDE for example .
Groovy is scripting language (Dynamically typed ) >> talk about it later >> the kotlin part
Dynamically typed ( code translated and checked on the fly )
First say “الحاجه ام الاختراع “ there was a need so they invent that tool.
زمان كان الموبايل فيلد مثلا بسيط جدا ومكنش فيه كميه البيزنس اللي موجوده دلوقتي
بس حاليا بقه الموضوع اكثر تعقيدا وتفاصيل اكتر
فبقي محتاجين اكتر نعمله اوتمايشن توفيرا للجهد والوقت
--- give education example Techer build type and student diverse in features, assets
Also their nowadays testing strategy to complete agile cycle frequently build
So imagine the pain of doing that manually manually every day merge resourec and apply code changes daily !!!.
So here IDEA of gradle : get something flexible to automate and customize the build process .
Based in what see nex >>
Gradle just do like kolin or actually ktlin do like them as they start first
خدوا الحلو من كل واحد وجمعوه في مكان واحد
-- ANT was build system flexible in design build targets
-- ivy smoothly can define dependencies in mange vs build targets
-- maven take from it project structure “POM” project object model in define modules
And build pom file to descripe module and their dependencies.
Also have centralized repos “mavencentral” now dayes moved to “centeral” repo
Pros >> define in xml يع يع
-- Gant write in groovy which in more nice that xml in maven .
-- also one of the biggest privilege is “incremental build” so not recommended to run clean task until you extremely needed it .
android {
compileOptions {
incremental false
}
}
Histiry line of Gradle
-- 2013 lunch plugiun for eclips and their was guide to migrate from maven to eclipse your android project ;’(. “Lot of pain”
-- 2015 start with android studio
Any build process is represented as graphe of tasks .
Why flexible ?? If you just want to run the unit tests, choose the task that does that . If you want to package an application, most builds have an assemble task for that or pick which build type u need to package .
--- Draw general graphe task and give Android ex of how to custom task custom application id
by both plugins and your own build scripts, >> our scripti is extension . plugin build android engineers and we customize ours values here .
Here’s it’s scr of sample of “:app:assembleDebug” When click in build Vf Debug build type .
Tasks consist of
(Actions >> action to do like copy or compile ) “compile source files “
(Inputs >> give the needed inputs as files or values ) “minSdkValue” “JAVA_HOME”
(output >> like export APK , JAR ,AAR files ) or gererate build folder .
Initialize like in android check > java home , SDK , NDK , kotlin plugin if theri
Check setting to see which modules will contribute .
Configuration like in android >> get Applications Id , minSDK ,so on , build type will run , and based on that determine their task graph .
Execution >> execute the tasks as we will see next in DEMO
-- see in DEMO >> below points
Talk about the project struchutre as dir for each module have “Src” dir
And each one have gradle module
Also the project level gradle
We will go next more for android spachically for android build and will see how it help in out case using gradle build
Consist of basic gradle build system
Adding to android gradle plugins with needed android spachipcally functions for android projects like
Plugins “android.application” or “android.library”
here it’s what is run behind >> show the flow of massive work will
Save by automate our build using gradle .
You can distribute to code to diff build targets each one customized
Like :
“applicatiobnIdSuffix” , “prifix”
“versionNameSuffix” , prefix too
By the way this sytax change based in version
As “Jini sdebuggable “ will be differnt in “gradle-experimental version guess”
Talk about apply diff progurad rules for each build type
You can distribute the code to diff build targets each one customized
Like :
“applicatiobnIdSuffix” , “prifix”
“versionNameSuffix” , prefix too
By the way this syntax change based in version
As “Jini debuggable “ will be different in “gradle-experimental version guess”
Talk about apply diff proguard rules for each build type
The flavors we use it actually when we just need to change some assets as example between free or paid flavor
--- check with demo
The flavors we use it actually when we just need to change some assets as example between free or paid flavor
--- check with demo
-- show in demo how will add src and res folders pre flavor
Talk about that at end all this res will be merged
-- DEMO show how we add res and src vs flavor or buildtype
-- talk about that you can link it easily with your code and their
No need to download and embedded it manually
If we make it maven centralized will get it and download it for us
-- define diff in syntax with ex of “twi:commonutil:1.0.9”
-- talk compile vs runtime will show in runtime only
- compile while resolve before compile and check it by default will in runtime too
- runtime resolve in run time only.
-- enable disabel trasive flags for library
-
--
- compile while resolve before compile and check it by default will in runtime too
- runtime resolve in run time only.
-- enable disabel trasive flags for library
-
-- we can define different sign Configuration
And manage them with different targets .
-- trye in DEMO
Kotlin will now injected in everything
So simply to go for everything with kotin
also it’s static and dynamic typing >> will avoid massive of typing errors
Static: Types checked before run-time
Dynamic: Types checked on the fly, during execution