SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
A Gradle Story
Eduardo Bonet
$ whoami
Bonet
Control and Automation Engineer
Master Student in Computer Science
Full Stack / Data Scientist Jr
Android Hobbyist
Agenda
● What is Gradle?
● Build Types and Variables
● Flavors
● Cool Tasks
Why Gradle?
Building and packaging an android app is complicated
Gradle is a build tool powered by Groovy
You CODE configurations
It's magical!
Introducing John
John is a CS student, and his dad has a bakery. He made an
app for his dad's bakery and wants to publish it.
John's First Problem
John tested his api calls on his local server during
development. He needs to change his client to point to the
new production server.
Error Prone!
Gradle Build Variables
John can improve it by moving the variable to build.config
build.gradle
BuildConfig already contains lots of goodies
Installing different versions of the app
build.gradle
Installing different versions of the app
BakeryAPP Identity Crisis
John will now split the app into two versions: free and
premium. Should he create a new app and copy/paste code?
How will that be maintained, what about new features?
Vanilla or Chocolate?
Product Flavors
Flavors - Multiple app versions
build.gradle
Flavors - Multiple app versions
src/ free /java/res/values/strings.xml
src/ pro /java/res/values/strings.xml
Not instead. Flavors WITH BuildTypes! They can be combined!
Why Flavors instead of BuildTypes?
Build Type
Flavor Debug Homolog Release
Free freeDebug freeHomolog freeRelease
Pro proDebug proHomolog proRelease
Customizing Flavors and BuildTypes
| -- src
| | --- test (java, res, assets)
| | --- main (java, res, assets)
| | --- free (java, res, assets)
| | --- pro (java, res, assets)
| | --- debug (java, res, assets)
| | --- freeDebug (java, res, assets)
Priority Order
flavorBuild > flavor > build > main
John now for some reason wants to add different behavior to
the flavors: all cakes for free version are stored in memory,
while only the pro version queries the API.
src/ pro /java/johnsdadbakery/
AwesomeCakeRepository.java
src/ free /java/johnsdadbakery/
AwesomeCakeRepository.java
Example: Specific Code with DI
The D on SOLID! This is where Dependency Injection shines. John first abstracts
the repo and builder into an interface, in the main source set.
src/java/ main /johnsdadbakery/ AwesomeCakeRepository.java
src/java/main/johnsdadbakery/ LocalCakeRepoBuilder.java
src/java/ main /johnsdadbakery/ RetrofitCakeRepoBuilder.java
Example: Specific Code with DI
Our injector interface will helps us configure flavor specific behaviour
src/java/main/johnsdadbakery/ InjectorInterface.java
Example: Specific Code with DI
Finally, we just need to implement the Injector interface on each flavor:
src/java/ free /johnsdadbakery/Injector.java
Example: Specific Code with DI
Finally, we just need to implement the Injector interface on each flavor:
src/java/ pro /johnsdadbakery/Injector.java
Example: Specific Code with DI
Now we simply ask the injector for the correct CakeRepo Implementation
This is a very naive DI implementation, consider using Dagger2, it is way more
powerful
John is tired of typing his Keystore credentials
John hates typing password every time he creates a release
version. Android Studio helps with that, but how a CI server
would handle it?
Gradle, do the thing!
Signing Configs
PASSWORD ON REPO
build.gradle
signing.props
Signing Config - Better
Lost in screenshots
John translated his app to three different languages. And has
support for multiple screens. That means every time he
publishes a new release he has to generate a LOT of
screenshots for the PlayStore.
● Create screenshots with Spoon https://github.com/stanfy/spoon-gradle-plugin
● Frame it with https://github.com/chemouna/frame-gradle-plugin
● Ta-da!
Another way: http://flavienlaurent.com/blog/2014/12/05/screenshot_automation/
Screenshot ALL THE THINGS
Screenshot ALL THE THINGS
Gradle make a Sandwich
Cool Gradle Plugins
Am I Pretty? CheckStyle
http://blog.jessitron.com/2012/07/using-checkstyle-in-gradle.html
http://checkstyle.sourceforge.net/config.html
http://www.slideshare.net/marcprengemann/better-code-through-lint-and-
checkstyle
OMG Google Play Services! - Dexcount
● https://github.com/mihaip/dex-method-counts
● https://github.com/KeepSafe/dexcount-gradle-plugin
Retrolambda - A great release task
And much more!
● Slack: https://github.com/Mindera/gradle-slack-plugin
● Upload to GooglePlay: https://github.com/Triple-T/gradle-play-publisher
● Git: https://github.com/ajoberstar/gradle-git
● Upload your lib to maven repos
…..
● Turn on your coffee machine: Not done yet :)
● Etc etc etc
What did John learn today?
● Gradle is a build tool written that runs on Groovy, sky is the limit
Know your build tool, it will help you a lot
Use Build Types to configure Environments
Use Flavors to create App Versions
Great Plugins out there to make you more productive and happy!
See also
● http://blog.brainattica.com/how-to-work-with-flavours-on-android/
● http://tools.android.com/tech-docs/new-build-system/user-guide
● http://gradle.org/
● http://gradleplease.appspot.com/
Thank you
github.com/ebonet
linkedin.com/in/eduardobonet

Contenu connexe

Tendances

Tendances (20)

How To Be A Better Developer
How To Be A Better DeveloperHow To Be A Better Developer
How To Be A Better Developer
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.io
 
Google flutter and why does it matter
Google flutter and why does it matterGoogle flutter and why does it matter
Google flutter and why does it matter
 
What's new in flutter and dart in 2020
 What's new in flutter and dart in 2020   What's new in flutter and dart in 2020
What's new in flutter and dart in 2020
 
Mobile Devolpment Slides
Mobile Devolpment SlidesMobile Devolpment Slides
Mobile Devolpment Slides
 
Flutter A year of creativity!
Flutter A year of creativity!Flutter A year of creativity!
Flutter A year of creativity!
 
The Magic of flutter Comex oman 2019
The Magic of flutter Comex oman 2019The Magic of flutter Comex oman 2019
The Magic of flutter Comex oman 2019
 
React Native "A Bad Idea Or A Game Changer" at Code Mania 101
React Native "A Bad Idea Or A Game Changer" at Code Mania 101React Native "A Bad Idea Or A Game Changer" at Code Mania 101
React Native "A Bad Idea Or A Game Changer" at Code Mania 101
 
Google flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE AlazharGoogle flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE Alazhar
 
The magic of flutter
The magic of flutterThe magic of flutter
The magic of flutter
 
Faisal Abid - Flutter for Android developers! - Codemotion Milan 2018
Faisal Abid - Flutter for Android developers! - Codemotion Milan 2018Faisal Abid - Flutter for Android developers! - Codemotion Milan 2018
Faisal Abid - Flutter for Android developers! - Codemotion Milan 2018
 
Google flutter the easy and practical way
Google flutter the easy and practical wayGoogle flutter the easy and practical way
Google flutter the easy and practical way
 
Build responsive applications with google flutter
Build responsive applications with  google flutterBuild responsive applications with  google flutter
Build responsive applications with google flutter
 
Building beautiful apps using google flutter
Building beautiful apps using google flutterBuilding beautiful apps using google flutter
Building beautiful apps using google flutter
 
Google flutter the easy and practical way
Google flutter the easy and practical wayGoogle flutter the easy and practical way
Google flutter the easy and practical way
 
Le novità di Xamarin e dello sviluppo Cross-Platform
Le novità di Xamarin e dello sviluppo Cross-PlatformLe novità di Xamarin e dello sviluppo Cross-Platform
Le novità di Xamarin e dello sviluppo Cross-Platform
 
Google flutter the easy and practical way
Google flutter the easy and practical wayGoogle flutter the easy and practical way
Google flutter the easy and practical way
 
Why companies like Google, Alibaba and UOL choose Flutter
Why companies like Google, Alibaba and UOL choose FlutterWhy companies like Google, Alibaba and UOL choose Flutter
Why companies like Google, Alibaba and UOL choose Flutter
 
JavaScript, React Native and Performance at react-europe 2016
JavaScript, React Native and Performance at react-europe 2016JavaScript, React Native and Performance at react-europe 2016
JavaScript, React Native and Performance at react-europe 2016
 
Flutter - DevFestDC
Flutter - DevFestDCFlutter - DevFestDC
Flutter - DevFestDC
 

En vedette

En vedette (20)

Usando POP com Programação Funcional
Usando POP com Programação FuncionalUsando POP com Programação Funcional
Usando POP com Programação Funcional
 
Devs dando pitacos
Devs dando pitacosDevs dando pitacos
Devs dando pitacos
 
Criando app Android utilizando Kotlin
Criando app Android utilizando KotlinCriando app Android utilizando Kotlin
Criando app Android utilizando Kotlin
 
Node.js, is it the solution for every problem?
Node.js, is it the solution for every problem?Node.js, is it the solution for every problem?
Node.js, is it the solution for every problem?
 
Android NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo NativoAndroid NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo Nativo
 
Reactive Programming no Android
Reactive Programming no AndroidReactive Programming no Android
Reactive Programming no Android
 
TDC Floripa - Trilha iOS - Mercado iOS no Brasil.
TDC Floripa - Trilha iOS - Mercado iOS no Brasil.TDC Floripa - Trilha iOS - Mercado iOS no Brasil.
TDC Floripa - Trilha iOS - Mercado iOS no Brasil.
 
Dev e designer em projetos de UX, vai ter briga?!
Dev e designer em projetos de UX, vai ter briga?!Dev e designer em projetos de UX, vai ter briga?!
Dev e designer em projetos de UX, vai ter briga?!
 
Gerenciamento de Memória em Swift - The Weak, the Strong, and the Unowned.
Gerenciamento de Memória em Swift - The Weak, the Strong, and the Unowned.Gerenciamento de Memória em Swift - The Weak, the Strong, and the Unowned.
Gerenciamento de Memória em Swift - The Weak, the Strong, and the Unowned.
 
TDC Floripa - Trilha iOS - Debate sobre o futuro da plataforma
TDC Floripa - Trilha iOS - Debate sobre o futuro da plataformaTDC Floripa - Trilha iOS - Debate sobre o futuro da plataforma
TDC Floripa - Trilha iOS - Debate sobre o futuro da plataforma
 
Sucesso e derrota na Arquitetura Agile
Sucesso e derrota na Arquitetura AgileSucesso e derrota na Arquitetura Agile
Sucesso e derrota na Arquitetura Agile
 
TDC2016SP - Vamos falar sobre o futuro da web: HTTP/2
TDC2016SP - Vamos falar sobre o futuro da web: HTTP/2TDC2016SP - Vamos falar sobre o futuro da web: HTTP/2
TDC2016SP - Vamos falar sobre o futuro da web: HTTP/2
 
TDC2016SP - Dinâmica e Facilitações
TDC2016SP - Dinâmica e FacilitaçõesTDC2016SP - Dinâmica e Facilitações
TDC2016SP - Dinâmica e Facilitações
 
TDC2016SP - Trilha NoSQL
TDC2016SP - Trilha NoSQLTDC2016SP - Trilha NoSQL
TDC2016SP - Trilha NoSQL
 
HHVM - Entre Nesse Ritmo - TDC Florianopolis 2014
HHVM - Entre Nesse Ritmo - TDC Florianopolis 2014HHVM - Entre Nesse Ritmo - TDC Florianopolis 2014
HHVM - Entre Nesse Ritmo - TDC Florianopolis 2014
 
TDC2016SP - Trilha Node.Js
TDC2016SP - Trilha Node.JsTDC2016SP - Trilha Node.Js
TDC2016SP - Trilha Node.Js
 
TDC2016SP - Trilha Startups
TDC2016SP - Trilha StartupsTDC2016SP - Trilha Startups
TDC2016SP - Trilha Startups
 
TDC2016SP - Mobile and APIs - Como a Mágica Acontece
TDC2016SP - Mobile and APIs - Como a Mágica AconteceTDC2016SP - Mobile and APIs - Como a Mágica Acontece
TDC2016SP - Mobile and APIs - Como a Mágica Acontece
 
TDC2016SP - Trilha DevOps Java
TDC2016SP - Trilha DevOps JavaTDC2016SP - Trilha DevOps Java
TDC2016SP - Trilha DevOps Java
 
TDC2016SP - Dinâmica e Facilitações
TDC2016SP - Dinâmica e FacilitaçõesTDC2016SP - Dinâmica e Facilitações
TDC2016SP - Dinâmica e Facilitações
 

Similaire à A Gradle Story

Udi Google Dev Day
Udi Google Dev DayUdi Google Dev Day
Udi Google Dev Day
Udi Bauman
 

Similaire à A Gradle Story (20)

Introduction to Cordova
Introduction to CordovaIntroduction to Cordova
Introduction to Cordova
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Auf Augenhöhe mit Android Studio und Gradle
Auf Augenhöhe mit Android Studio und GradleAuf Augenhöhe mit Android Studio und Gradle
Auf Augenhöhe mit Android Studio und Gradle
 
Android Studio und gradle
Android Studio und gradleAndroid Studio und gradle
Android Studio und gradle
 
Gradle-based Android Build System
Gradle-based Android Build SystemGradle-based Android Build System
Gradle-based Android Build System
 
React Native - CirebonDev
React Native - CirebonDevReact Native - CirebonDev
React Native - CirebonDev
 
Rational Rhapsody Workflow Integration with Visual Studio
Rational Rhapsody Workflow Integration with Visual Studio Rational Rhapsody Workflow Integration with Visual Studio
Rational Rhapsody Workflow Integration with Visual Studio
 
Cordova + Ionic + MobileFirst
Cordova + Ionic + MobileFirstCordova + Ionic + MobileFirst
Cordova + Ionic + MobileFirst
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
 
Udi Google Dev Day
Udi Google Dev DayUdi Google Dev Day
Udi Google Dev Day
 
Creating books app with react native
Creating books app with react nativeCreating books app with react native
Creating books app with react native
 
Flutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textFlutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - text
 
Frontend Workflow
Frontend WorkflowFrontend Workflow
Frontend Workflow
 
Gradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of FriendsGradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of Friends
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)
 
Rene Groeschke
Rene GroeschkeRene Groeschke
Rene Groeschke
 
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
 
Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matter
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & Beyond
 
Writing Performant Front-end Code
Writing Performant Front-end CodeWriting Performant Front-end Code
Writing Performant Front-end Code
 

Plus de Eduardo Felipe Ewert Bonet

Plus de Eduardo Felipe Ewert Bonet (6)

Usando Java 8 no Android
Usando Java 8 no AndroidUsando Java 8 no Android
Usando Java 8 no Android
 
Using Java 8 on Android
Using Java 8 on AndroidUsing Java 8 on Android
Using Java 8 on Android
 
Testing in go
Testing in goTesting in go
Testing in go
 
Testes em go
Testes em goTestes em go
Testes em go
 
Python e R: uma comparação prática
Python e R: uma comparação práticaPython e R: uma comparação prática
Python e R: uma comparação prática
 
Data Science For Dummies From a Dummy
Data Science For Dummies From a DummyData Science For Dummies From a Dummy
Data Science For Dummies From a Dummy
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

A Gradle Story