- Groovy can be used to create Android apps and provides features like domain classes, closures, and traits that make development more concise and readable compared to Java.
- A Groovy Android app can be created using the Lazybones template tool or the Android Studio wizard by adding Groovy dependencies. The app is then built with Gradle.
- Groovy provides features out of the box like safe null checking, functional programming with closures, and domain-specific languages that simplify common tasks in Android. Additional libraries allow reactive and testing functionality.
2. About me
● Mario Garcia
– Software engineer at Kaleidos
https://github.com/mariogarcia
@marioggar
3. Before I begin...
● Thanks to Tuenti
● Disclaimer
– I'm not an Android developer
– Questions welcomed :)
4. What is this talk about ?
● Summary
– Android is NOT ONLY Java
– Your first Grooid app
– Groovy features
– Useful libraries
– Reactive
– Testing
– Q & A
5. Android is NOT ONLY Java
● Why not Groovy ?
– Why not… ?
– Chose your poison:
7. Create your first Groovy app
● The Android Studio wizard
– Meant for Java
– If you go this way, then:
● Create a Java app through the wizard
● Add Groovy/Gradle plugin
● Add needed basic dependencies
● …
8. Create your first Groovy app
● A better way:
– Create a basic skeleton with Lazybones
– Import as Gradle project to Android Studio
– Profit!
9. Create your first Groovy app
● Lazybones
– A simple project creation tool
– Templates
– Really easy to use and extend
10. Create your first Groovy app
● Grooid templates
– Lazybones templates for creating:
● Android app, Android lib
● Coming soon: Google Glass app
11. Create your first Groovy app
● Gradle
– Android Reference build tool
– Convention over Configuration
– Still thinking of Maven ? check this out:
● https://gradle.org/maven_vs_gradle/
12. Create your first Groovy app
● Android Studio
– Reference IDE based on Intellij IDEA
– Really helpful specially for UI
– Integrates perfectly with Gradle projects
15. Groovy features
● Domain classes
● Get rid of accessors
● No need to override constructors
● More AST to do pumbling staf
– @AutoExternalize
– @Canonical
– @Immutable
– @InheritConstructors
– …. many more
18. Groovy features
● GDK
– Groovy extensions to the JDK
● Groovy collections (collect/inject/find)
● Safe methods to deal with JDK Classes
– e.g: take(int) : use it instead of substring
19. Groovy features
● NPE and Exceptions
– NPE
● ? operator
● * operator
● Elvis :?
– Exceptions
● Go functional || Reactive
– FNZ: Try<T>, Maybe<T>
– RxJava/RxAndroid: onError()
22. Groovy features
● Closures
● No need to create inner classes anymore
● Wherever there is a Functional Interface you can
use a Closure
● Also useful when creating DSLs
26. Groovy features
● Traits
– Have you ever wanted to share some
functionality between an Activity and a
ListActivity ?
● Another way to share functionality among class
hierarchies
● Used as if it were an interface
● IDE friendly
29. Advanced features
● Extension Modules
– Add new functionality to existing code
– Easy to use and program
● Just classes with static methods
● Android Studio recognizes Extension Modules out-of-
the-box
31. Advanced features
● Custom ASTs
– Add new functionality to existing code
● During compilation time
● Extremely powerful
● No need for an annotation-processor
● Harder to code than Extension Modules
35. Advanced features
● Swissknife
– Makes easier to deal with view injection and
threading nightmare.
● Based on AndroidAnnotations and ButterKnife
● Collection of: ASTs, DSLs, Extension Modules
40. Testing
● Spock
– A better way of testing
● DSL to describe your tests in a fluent way
● Compatible with JUnit
41. Testing
● AndroidSpock
– Create integration tests
● Under src/androidTest/groovy
● Helpers to inject and initialize activities in your tests
● Deploys and run tests in the device
42. Testing
● Robospock
– Create unit tests
● Based on roboelectric 3.0
● no DEXing or deployment time is wasted to execute
your unit tests.
43. Other tools
● Quality code
– Codenarc
● Static analysis for Groovy
● Highly Configurable
● Completely integrated with Gradle