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

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
Wojciech 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 2019
Horgix
 

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

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

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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