SlideShare a Scribd company logo
1 of 53
Download to read offline
1 
Android and Groovy
2 
Mario Garcia 
Software Engineer 
Happily Working for 
@marioggar
3 
Let me tell you a story...
4 
Long Long time ago.... 
There was a back-end developer ...
5 
Long Long time ago.... 
He used to code using Groovy
6 
Long Long time ago.... 
But not all was happiness... 
At the beginning Groovy couldn't 
Work on Android
7 
But finally that day came.... 
During the GR8Conf...
8 
Cedric Champeau 
core developer 
Yes now you can!!! 
Released Groovy 2.4 :grooid 
Thanks 
Cedric!!!!
9
10 
He took his mobile and.... 
Every seemed to be awesome 
but then ...
11 
Light became darkness because....
12 
Darkest hour 
No background on Android development 
Activity 
Fragment 
Layouts 
Adapters 
UIThread 
Bla bla... 
Bla bla... 
Bla bla...
13 
Darkest hour 
Almost no docs about Groovy on Android 
Cedric Champeau 
Blog http://melix.github.io/blog/ 
Github https://github.com/melix
14 
Create the first project.... 
Tools, tools everywhere 
...
15 
Two paths 
%
16 
The Gradle Path 
Grab some of Cedric's projects 
Add what you need and build it 
Import to AS
17 
Gradle 
Hey is Groovy!! 
Less verbose than Maven 
Is code not XML 
Polyglot 
Same build tool for different languages 
At some point it should set you free from any IDE
18 
Gradle 
Plugins
19 
Gradle 
Android SDKs version
20 
Gradle 
Dependencies
21 
Android Studio 
Import your Gradle app
22 
Android Studio 
Project structure
23 
Java Path (Android Studio) 
Ask AS to create a Java project 
Add Cedric plugin 
Keep working
24 
Android Studio 
Or create a new Android/Gradle project
25 
He swore he would never... 
How can avoid repeating 
the whole process again ?
26 
Wish list 
Basic working Groovy skeleton 
Basic helpful dependencies to make my life less miserable 
Add Asciidoctor :) 
Add whatever you want...
27 
Lazybones 
What's lazybones 
A simple project creation tool that uses packaged project 
templates. 
Created by: Peter Leedbrook 
https://github.com/pledbrook/lazybones
28 
Lazybones 
With lazy bones he could: 
Basic working Groovy skeleton... 
DONE 
Basic dependencies to make my life less miserable... 
Add Asciidoctor... 
Add whatever you want... 
DONE 
DONE
29 
SHOW ME THE CODE 
How Groovy can help you ?
30 
Groovy by default 
At the beginning everything looked like Java:
31 
Groovy by default 
But even then if you looked a little bit closer... 
Some Groovy basic AST transformations saved precious lines 
Get rid of accessors
32 
Groovy by default 
Bean construction: 
Using map constructor:
33 
Groovy collections and more... 
Collections were more fun 
Filtering and mapping (find/collect)
34 
Closures 
Turn functional interfaces to functions (I): 
Whenever you have to implement an interface with just one method you can 
use a closure
35 
Closures 
Turn functional interfaces to functions (II): 
Whenever you have to implement an interface with just one method you can 
use a closure
36 
Closures - Fn 
Currying and MethodClosure: 
Plain Java methods can become high order functions
37 
Closures 
Functional Interface coertion:
38 
Traits 
Traits: 
Sometimes you have to extend different clases but still want to share some 
common behavior. (Activities/ListActivity) 
There are red lines 
because Android Studio 
doesn't recognize 
Traits...yet
39 
AST Transformations 
ASTs: 
Anytime you fill there is boilerplate code there is work for an AST to do 
You can create your own 
@ASTTest 
@AnnotationCollector 
@AutoClone 
@AutoExternalize 
@Canonical 
@ConditionalInterrupt 
@EqualsAndHashcode 
@Field 
@Immutable 
@IndexedProperty 
@InheritConstructors 
@Memoized 
@Sortable 
@TailRecursive 
@ThreadInterrupt 
@Trait 
@ToString 
@TupleConstructor 
@TypeChecked 
@Log 
@Log4j 
Still a few more
40 
SwissKnife 
A multi-purpose Groovy library containing view injection and threading for 
Android using annotations. It's based on both ButterKnife and 
AndroidAnnotations
41 
SwissKnife 
Injecting Views. Forget about findViewById
42 
SwissKnife 
@OnBackground and @UIThread 
@OnBackground 
Creates an async task 
@UIThread 
It gets a handler instance to run the body in the UI thread
43 
SwissKnife 
@OnBackground and @UIThread
44 
SwissKnife 
@OnClick, @OnItemSelected... 
There are several other annotations for annotating methods you want to be 
triggered when an event occurs
45 
Grooid-tools 
A DSL for generating views with Groovy 
https://github.com/karfunkel/grooid-tools 
For example create a TextView 
s
46 
What about performance ? 
Faster, cleaner, cheaper...
47 
Performance 
Before blaming the language you may want to check if the 
problem is elsewhere ;)
48 
Performance 
@CompileStatic: 
It optimizes bytecode applying static check compilation 
Sorry, I don't have benchmarks on Android 
In the JDK we're doing well with InvokeDynamic 
On Android is advisable to use it...what please don't freak 
out !
49 
Performance 
http://open.blogs.nytimes.com/2014/08/?_r=0
50 
What's next ? 
The future
51 
Android Wear 
Stay tuned at 
http://melix.github.io/blog/
52 
Who knows ? 
Groovy Groovy everywhere
53 
Thank you … 
Q & A

More Related Content

Similar to Groovy on Android

Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1benDesigning
 
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...Ambassador Labs
 
Making Security Invisible
Making Security InvisibleMaking Security Invisible
Making Security InvisibleJ On The Beach
 
I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...Neil Crosby
 
Show you mine
Show you mineShow you mine
Show you mineviemonde
 
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / ConspectKo Turk
 
JVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEsJVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEsKo Turk
 
Understanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptUnderstanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptDarren Adkinson
 
Building an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedWojciech Koszek
 
Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019Horgix
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0André Moreira
 
Prototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo TodonePrototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo TodoneCodemotion
 
App inventor presentation
App inventor presentationApp inventor presentation
App inventor presentationAndrew Kamau
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)YangJerng Hwa
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
Openstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud FrameworkOpenstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud FrameworkAndrew Shafer
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 

Similar to Groovy on Android (20)

Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
 
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
 
Making Security Invisible
Making Security InvisibleMaking Security Invisible
Making Security Invisible
 
I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...
 
Show you mine
Show you mineShow you mine
Show you mine
 
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
05092019 The Battle of the IDEs by Ko Turk at the AlmereJUG / Conspect
 
JVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEsJVM Conference - The Battle of the IDEs
JVM Conference - The Battle of the IDEs
 
Understanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptUnderstanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScript
 
Building an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learned
 
SWT - Technical Deep Dive
SWT - Technical Deep DiveSWT - Technical Deep Dive
SWT - Technical Deep Dive
 
Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019Kubernetes IN Docker: Next level inception - Paris Container Day 2019
Kubernetes IN Docker: Next level inception - Paris Container Day 2019
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0
 
Prototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo TodonePrototipazione rapida con C# e Unity3D by Giancarlo Todone
Prototipazione rapida con C# e Unity3D by Giancarlo Todone
 
App inventor presentation
App inventor presentationApp inventor presentation
App inventor presentation
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
Openstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud FrameworkOpenstack: An Open Source Cloud Framework
Openstack: An Open Source Cloud Framework
 
Groovy android
Groovy androidGroovy android
Groovy android
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 

More from Mario García

Blockchain 101 (spanish)
Blockchain 101 (spanish)Blockchain 101 (spanish)
Blockchain 101 (spanish)Mario García
 
Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Mario García
 
Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)Mario García
 
Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)Mario García
 
Macro macro, burrito burrit
Macro macro, burrito burritMacro macro, burrito burrit
Macro macro, burrito burritMario García
 
Creating ASTTs The painful truth
Creating ASTTs The painful truthCreating ASTTs The painful truth
Creating ASTTs The painful truthMario García
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyMario García
 
Test Motherfucker...Test
Test Motherfucker...TestTest Motherfucker...Test
Test Motherfucker...TestMario García
 
Programación concurrente con GPars
Programación concurrente con GParsProgramación concurrente con GPars
Programación concurrente con GParsMario García
 
Greach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con GriffonGreach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con GriffonMario García
 

More from Mario García (15)

Blockchain 101 (spanish)
Blockchain 101 (spanish)Blockchain 101 (spanish)
Blockchain 101 (spanish)
 
Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)
 
Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)Groovy 2.5 and 3.0 (Spanish)
Groovy 2.5 and 3.0 (Spanish)
 
GraphQL & Ratpack
GraphQL & RatpackGraphQL & Ratpack
GraphQL & Ratpack
 
GraphQL y Groovy
GraphQL y GroovyGraphQL y Groovy
GraphQL y Groovy
 
Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)Calidad del codigo (MadridGUG)
Calidad del codigo (MadridGUG)
 
GraphQL and Groovy
GraphQL and GroovyGraphQL and Groovy
GraphQL and Groovy
 
Macro macro, burrito burrit
Macro macro, burrito burritMacro macro, burrito burrit
Macro macro, burrito burrit
 
Creating ASTTs The painful truth
Creating ASTTs The painful truthCreating ASTTs The painful truth
Creating ASTTs The painful truth
 
Gpars Workshop 2014
Gpars Workshop 2014Gpars Workshop 2014
Gpars Workshop 2014
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Test Motherfucker...Test
Test Motherfucker...TestTest Motherfucker...Test
Test Motherfucker...Test
 
Programación concurrente con GPars
Programación concurrente con GParsProgramación concurrente con GPars
Programación concurrente con GPars
 
Gradle vs Maven
Gradle vs MavenGradle vs Maven
Gradle vs Maven
 
Greach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con GriffonGreach 2011 : Creando Plugins Con Griffon
Greach 2011 : Creando Plugins Con Griffon
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

Groovy on Android

  • 1. 1 Android and Groovy
  • 2. 2 Mario Garcia Software Engineer Happily Working for @marioggar
  • 3. 3 Let me tell you a story...
  • 4. 4 Long Long time ago.... There was a back-end developer ...
  • 5. 5 Long Long time ago.... He used to code using Groovy
  • 6. 6 Long Long time ago.... But not all was happiness... At the beginning Groovy couldn't Work on Android
  • 7. 7 But finally that day came.... During the GR8Conf...
  • 8. 8 Cedric Champeau core developer Yes now you can!!! Released Groovy 2.4 :grooid Thanks Cedric!!!!
  • 9. 9
  • 10. 10 He took his mobile and.... Every seemed to be awesome but then ...
  • 11. 11 Light became darkness because....
  • 12. 12 Darkest hour No background on Android development Activity Fragment Layouts Adapters UIThread Bla bla... Bla bla... Bla bla...
  • 13. 13 Darkest hour Almost no docs about Groovy on Android Cedric Champeau Blog http://melix.github.io/blog/ Github https://github.com/melix
  • 14. 14 Create the first project.... Tools, tools everywhere ...
  • 16. 16 The Gradle Path Grab some of Cedric's projects Add what you need and build it Import to AS
  • 17. 17 Gradle Hey is Groovy!! Less verbose than Maven Is code not XML Polyglot Same build tool for different languages At some point it should set you free from any IDE
  • 19. 19 Gradle Android SDKs version
  • 21. 21 Android Studio Import your Gradle app
  • 22. 22 Android Studio Project structure
  • 23. 23 Java Path (Android Studio) Ask AS to create a Java project Add Cedric plugin Keep working
  • 24. 24 Android Studio Or create a new Android/Gradle project
  • 25. 25 He swore he would never... How can avoid repeating the whole process again ?
  • 26. 26 Wish list Basic working Groovy skeleton Basic helpful dependencies to make my life less miserable Add Asciidoctor :) Add whatever you want...
  • 27. 27 Lazybones What's lazybones A simple project creation tool that uses packaged project templates. Created by: Peter Leedbrook https://github.com/pledbrook/lazybones
  • 28. 28 Lazybones With lazy bones he could: Basic working Groovy skeleton... DONE Basic dependencies to make my life less miserable... Add Asciidoctor... Add whatever you want... DONE DONE
  • 29. 29 SHOW ME THE CODE How Groovy can help you ?
  • 30. 30 Groovy by default At the beginning everything looked like Java:
  • 31. 31 Groovy by default But even then if you looked a little bit closer... Some Groovy basic AST transformations saved precious lines Get rid of accessors
  • 32. 32 Groovy by default Bean construction: Using map constructor:
  • 33. 33 Groovy collections and more... Collections were more fun Filtering and mapping (find/collect)
  • 34. 34 Closures Turn functional interfaces to functions (I): Whenever you have to implement an interface with just one method you can use a closure
  • 35. 35 Closures Turn functional interfaces to functions (II): Whenever you have to implement an interface with just one method you can use a closure
  • 36. 36 Closures - Fn Currying and MethodClosure: Plain Java methods can become high order functions
  • 37. 37 Closures Functional Interface coertion:
  • 38. 38 Traits Traits: Sometimes you have to extend different clases but still want to share some common behavior. (Activities/ListActivity) There are red lines because Android Studio doesn't recognize Traits...yet
  • 39. 39 AST Transformations ASTs: Anytime you fill there is boilerplate code there is work for an AST to do You can create your own @ASTTest @AnnotationCollector @AutoClone @AutoExternalize @Canonical @ConditionalInterrupt @EqualsAndHashcode @Field @Immutable @IndexedProperty @InheritConstructors @Memoized @Sortable @TailRecursive @ThreadInterrupt @Trait @ToString @TupleConstructor @TypeChecked @Log @Log4j Still a few more
  • 40. 40 SwissKnife A multi-purpose Groovy library containing view injection and threading for Android using annotations. It's based on both ButterKnife and AndroidAnnotations
  • 41. 41 SwissKnife Injecting Views. Forget about findViewById
  • 42. 42 SwissKnife @OnBackground and @UIThread @OnBackground Creates an async task @UIThread It gets a handler instance to run the body in the UI thread
  • 44. 44 SwissKnife @OnClick, @OnItemSelected... There are several other annotations for annotating methods you want to be triggered when an event occurs
  • 45. 45 Grooid-tools A DSL for generating views with Groovy https://github.com/karfunkel/grooid-tools For example create a TextView s
  • 46. 46 What about performance ? Faster, cleaner, cheaper...
  • 47. 47 Performance Before blaming the language you may want to check if the problem is elsewhere ;)
  • 48. 48 Performance @CompileStatic: It optimizes bytecode applying static check compilation Sorry, I don't have benchmarks on Android In the JDK we're doing well with InvokeDynamic On Android is advisable to use it...what please don't freak out !
  • 50. 50 What's next ? The future
  • 51. 51 Android Wear Stay tuned at http://melix.github.io/blog/
  • 52. 52 Who knows ? Groovy Groovy everywhere
  • 53. 53 Thank you … Q & A