SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
Android Best Practices
Agenda
● Introduction
● The clean architecture
● Testing
● Support library
● Libraries we can depend on
● What's next
Introduction
Android Studio
Gradle
Material Design
Lollipop
Android
Wear / Auto / TV
Introduction
The clean architecture
The clean architecture
The key concept is based on:
● Independence of frameworks
● Testeable
● Independent of UI
● Independent of DB
● Independent of any external agency
The clean architecture
Definitions
● Entities: These are the business objects of
the application
● Use Cases: These use cases orchestrate the
flow of data to and from the entities.
● Interface Adapters: This set of adapters
convert data from the format most
convenient for the use cases and entities.
● Frameworks and Drivers: This is where all
the details go: UI, tools, frameworks, etc.
Android architecture
The objective is the separation of concerns by keeping the business rules not knowing anything at all about the
outside world, thus, they can can be tested without any dependency to any external element.
To achieve this, the proposal is about breaking up the project into 3 different layers, in which each one has its own
purpose and works separately from the others.
Presentation layer
Is here, where the logic related with views and animations happens. It uses no more than a Model View Presenter
(MVP), but you can use any other pattern like MVC or MVVM.
For example, fragments and activities are only views, there is no logic inside them other than UI logic, and this is
where all the rendering stuff takes place.
Presenters in this layer are composed with interactors (use cases)
that perform the job in a new thread outside the android UI thread,
and come back using a callback with the data that will be rendered in
the view.
Domain layer
Business rules here: all the logic happens in this layer. Regarding the
android project, you will see all the interactors (use cases)
implementations here as well.
This layer is a pure java module without any android dependencies. All
the external components use interfaces when connecting to the
business objects.
Data layer
All data needed for the application comes from this layer through a Repository implementation (the interface is in the
domain layer) that uses a Repository Pattern with a strategy that, through a factory, picks different data sources
depending on certain conditions.
The idea behind all this is that the data origin
is transparent for the client, which does not
care if the data is coming from memory, disk
or the cloud, the only truth is that the data
will arrive and will be got.
Project structure
Presentation module
Is the Android application itself, with its resources,
assets, logic, etc.
Project structure
Domain module
This module hosts use-cases and their implementations,
it is the business logic of the application.
Project structure
Model module
This module is responsible for managing the
information, select, save, delete, etc.
Communication
Now, how we communicate these layers?
One approach is communication over an Message
Bus system. This system is very useful for
Broadcast events, or to establish a
communication between components.
Basically, events are sent through a Bus and the
classes interested to consume that event have to
subscribe to that Bus.
To implement the system bus, we used the library
Otto by Square, but we can use EventBus by
GreenRobot too. Both libraries implements the
publish/subscribe pattern.
Communication
Testing
Testing
We have different solutions for each layer:
● Presentation Layer: Android instrumentation and Espresso for integration and functional
testing
● Domain Layer: JUnit plus Mockito for unit tests
● Data Layer: Robolectric (since this layer has android dependencies) plus JUnit plus Mockito for
integration and unit tests.
Espresso
Espresso is a testing framework that exposes a simple API to perform UI testing of Android apps. With the latest 2.0
release, Espresso is now part of the Android Support Repository which makes it more easier to add automated testing
support for your project.
Key features:
● Its code looks a lot like English, which makes it predictable and easy to learn.
● The API is relatively small, and yet open for customization.
● Espresso tests run optimally fast (no waits, sleeps)
● Gradle + Android Studio support
Espresso
Is built up from 3 major components:
These components are:
● ViewMatchers – allows you to locate a view in the current view hierarchy
● ViewActions – allows you to interact with views
● ViewAssertions – allows you to assert the state of a view.
For simplicity, you may use these shortcuts to refer to them:
● ViewMatchers – “find something“
● ViewActions – “do something“
● ViewAssertions – “check something“
Espresso
Here is an example for this:
Espresso
Here is an example for this:
JUnit
JUnit in version 4.x is a test framework which uses annotations to identify methods that specify a test.
JUnit
From Android Studio 1.1, we have fully integration with JUnit.
Support Library
Support Library
Design Support Library
This library implements some custom views from Material Design such as:
NEW
Support Library
Design Support Library
Support Library
V7 Appcompat Library - IMPORTANT!!!
This library adds support from API V7 (Android 2.1) for basic
elements:
● Toolbar
● CardView
● GridLayout
● PaletteLibrary
● RecyclerView
● … and more
Support Library
V4 Support Library
This library adds support from API V4 (Android 1.6) for basic
elements:
● Fragment
● NotificationCompat
● ViewPager
● PagerTitle
● DrawerLayout
● ... and a lot more
Support Library
Testing Support Library
This library provides an extensive framework for testing Android apps. You can run tests created
using these APIs from the Android Studio IDE or from the command line.
Includes the following test automation tools:
● AndroidJUnitRunner: JUnit 4-compatible test runner for Android
● Espresso: UI testing framework; suitable for functional UI testing within an app
● UI Automator: UI testing framework; suitable for cross-app functional UI testing across
system and installed apps
Libraries we can depend on
Why libraries?
● Maintained by the community
● Easy to use
● Well documented
● It just works!!!
● Don't reinvent the wheel!!!
Retrofit
Type-safe REST client for Android and Java by Square, Inc.
Retrofit turns your REST API into a Java interface.
The RestAdapter class generates an implementation of the GitHubService interface.
Retrofit
Each call on the generated GitHubService makes an HTTP request to the remote webserver.
More examples:
Picasso
Image transformation
Picasso allows for hassle-free image loading in your application — often in one line of code!
ButterKnife
View injection library
Annotate fields with @InjectView and a view ID for Butter Knife to find and automatically cast the corresponding view
in your layout.
Gson
Gson is a Java library that can be used to convert Java Objects into their JSON representation. It
can also be used to convert a JSON string to an equivalent Java object.
Gson
We can customize named fields, this improves code readability:
Stetho
Stetho is a sophisticated debug bridge for
Android applications.
When enabled, developers have access to
the Chrome Developer Tools feature
natively part of the Chrome desktop
browser.
How?
Adding this libraries to our project it's really easy.
This libraries are located in two main repositories:
● Maven Central
● JCenter - Default on Android Studio
On our build.gradle file, we add:
Finding libraries
Android Arsenal Gradle, please
What’s next?
Finding libraries
● RXJava - Reactive Programming
● Dagger2 - Dependency Injection
● Kotlin - New scripting language
References
● Robert Martin - The Clean Architecture
● Fernando Cejas - The Clean Architecture
● Gradle - Android Tools
● Android Developers - Support Libraries
● Design Support Library Examples - Repository
● Retrofit - REST Adapter
● Picasso - Image loader
● Gson - JSON parser
● Stetho - View inspector
● Espresso - Samples
● Android Arsenal - For libraries / Gradle Please - Gradle dependencies
Thanks

Weitere ähnliche Inhalte

Was ist angesagt?

Test Automation On Android Platform Using Robotium
Test Automation On Android Platform Using RobotiumTest Automation On Android Platform Using Robotium
Test Automation On Android Platform Using RobotiumIndicThreads
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)Prateek Jain
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter rendra toro
 
Android studio 2.0: default project structure
Android studio 2.0: default project structureAndroid studio 2.0: default project structure
Android studio 2.0: default project structureVyara Georgieva
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Androidintive
 
Utilizando Espresso e UIAutomator no Teste de Apps Android
Utilizando Espresso e UIAutomator no Teste de Apps AndroidUtilizando Espresso e UIAutomator no Teste de Apps Android
Utilizando Espresso e UIAutomator no Teste de Apps AndroidEduardo Carrara de Araujo
 
JUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMJUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMVMware Tanzu
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Android studio&Gradle&Autotest
Android studio&Gradle&AutotestAndroid studio&Gradle&Autotest
Android studio&Gradle&Autotest毅 方
 
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...DicodingEvent
 
Getting started with dagger 2
Getting started with dagger 2Getting started with dagger 2
Getting started with dagger 2Rodrigo Henriques
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target PlatformsMickael Istria
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on androidBenjamin Cheng
 
Choosing the Best Open Source Test Automation Tool for You
Choosing the Best Open Source Test Automation Tool for YouChoosing the Best Open Source Test Automation Tool for You
Choosing the Best Open Source Test Automation Tool for YouPerfecto by Perforce
 
Advance appium workshop.pptx
Advance appium workshop.pptxAdvance appium workshop.pptx
Advance appium workshop.pptxVodqaBLR
 
Mobile applications and automation testing
Mobile applications and automation testingMobile applications and automation testing
Mobile applications and automation testingIndicThreads
 
How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?Paul Cook
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 

Was ist angesagt? (20)

Test Automation On Android Platform Using Robotium
Test Automation On Android Platform Using RobotiumTest Automation On Android Platform Using Robotium
Test Automation On Android Platform Using Robotium
 
Android
AndroidAndroid
Android
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter
 
Android studio 2.0: default project structure
Android studio 2.0: default project structureAndroid studio 2.0: default project structure
Android studio 2.0: default project structure
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Android
 
Utilizando Espresso e UIAutomator no Teste de Apps Android
Utilizando Espresso e UIAutomator no Teste de Apps AndroidUtilizando Espresso e UIAutomator no Teste de Apps Android
Utilizando Espresso e UIAutomator no Teste de Apps Android
 
JUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMJUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVM
 
Android Test Automation Workshop
Android Test Automation WorkshopAndroid Test Automation Workshop
Android Test Automation Workshop
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Android studio&Gradle&Autotest
Android studio&Gradle&AutotestAndroid studio&Gradle&Autotest
Android studio&Gradle&Autotest
 
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
 
Getting started with dagger 2
Getting started with dagger 2Getting started with dagger 2
Getting started with dagger 2
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target Platforms
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
 
Choosing the Best Open Source Test Automation Tool for You
Choosing the Best Open Source Test Automation Tool for YouChoosing the Best Open Source Test Automation Tool for You
Choosing the Best Open Source Test Automation Tool for You
 
Advance appium workshop.pptx
Advance appium workshop.pptxAdvance appium workshop.pptx
Advance appium workshop.pptx
 
Mobile applications and automation testing
Mobile applications and automation testingMobile applications and automation testing
Mobile applications and automation testing
 
How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?How Android Architecture Components can Help You Improve Your App’s Design?
How Android Architecture Components can Help You Improve Your App’s Design?
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 

Ähnlich wie Android Best Practices: Clean Architecture, Testing, Libraries

summer file - Copy
summer file - Copysummer file - Copy
summer file - CopyRakesh Kumar
 
Android app development SEO Expert Bangladesh LTD.pdf
Android app development  SEO Expert Bangladesh LTD.pdfAndroid app development  SEO Expert Bangladesh LTD.pdf
Android app development SEO Expert Bangladesh LTD.pdfTasnim Jahan
 
Android app development SEO Expert Bangladesh LTD.pdf
Android app development  SEO Expert Bangladesh LTD.pdfAndroid app development  SEO Expert Bangladesh LTD.pdf
Android app development SEO Expert Bangladesh LTD.pdfTasnim Jahan
 
RT Lab Android Application
RT Lab Android ApplicationRT Lab Android Application
RT Lab Android ApplicationPraahas Amin
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_authlzongren
 
[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Androidrizki adam kurniawan
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...DicodingEvent
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionMatteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionDuckMa
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshareSaleemMalik52
 
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanCara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanDicodingEvent
 
architecture of android.pptx
architecture of android.pptxarchitecture of android.pptx
architecture of android.pptxallurestore
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 
Top 7 react developer tools to use in 2021
Top 7 react developer tools to use in 2021Top 7 react developer tools to use in 2021
Top 7 react developer tools to use in 2021WrapPixel
 
From Containerization to Modularity
From Containerization to ModularityFrom Containerization to Modularity
From Containerization to Modularityoasisfeng
 
Mobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and DockerMobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and DockerMoataz Nabil
 
6 Top Debugging Tools for Angular Developers
6 Top Debugging Tools for Angular Developers6 Top Debugging Tools for Angular Developers
6 Top Debugging Tools for Angular DevelopersZipy1
 

Ähnlich wie Android Best Practices: Clean Architecture, Testing, Libraries (20)

summer file - Copy
summer file - Copysummer file - Copy
summer file - Copy
 
Android app development SEO Expert Bangladesh LTD.pdf
Android app development  SEO Expert Bangladesh LTD.pdfAndroid app development  SEO Expert Bangladesh LTD.pdf
Android app development SEO Expert Bangladesh LTD.pdf
 
Android app development SEO Expert Bangladesh LTD.pdf
Android app development  SEO Expert Bangladesh LTD.pdfAndroid app development  SEO Expert Bangladesh LTD.pdf
Android app development SEO Expert Bangladesh LTD.pdf
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
Intro to android (gdays)
Intro to android (gdays)Intro to android (gdays)
Intro to android (gdays)
 
RT Lab Android Application
RT Lab Android ApplicationRT Lab Android Application
RT Lab Android Application
 
Stmik bandung
Stmik bandungStmik bandung
Stmik bandung
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionMatteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
 
Android crash course
Android crash courseAndroid crash course
Android crash course
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanCara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
 
architecture of android.pptx
architecture of android.pptxarchitecture of android.pptx
architecture of android.pptx
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Top 7 react developer tools to use in 2021
Top 7 react developer tools to use in 2021Top 7 react developer tools to use in 2021
Top 7 react developer tools to use in 2021
 
From Containerization to Modularity
From Containerization to ModularityFrom Containerization to Modularity
From Containerization to Modularity
 
Mobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and DockerMobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and Docker
 
6 Top Debugging Tools for Angular Developers
6 Top Debugging Tools for Angular Developers6 Top Debugging Tools for Angular Developers
6 Top Debugging Tools for Angular Developers
 

Kürzlich hochgeladen

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 WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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.pptxMalak Abu Hammad
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Kürzlich hochgeladen (20)

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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

Android Best Practices: Clean Architecture, Testing, Libraries

  • 1.
  • 3. Agenda ● Introduction ● The clean architecture ● Testing ● Support library ● Libraries we can depend on ● What's next
  • 7. The clean architecture The key concept is based on: ● Independence of frameworks ● Testeable ● Independent of UI ● Independent of DB ● Independent of any external agency
  • 8. The clean architecture Definitions ● Entities: These are the business objects of the application ● Use Cases: These use cases orchestrate the flow of data to and from the entities. ● Interface Adapters: This set of adapters convert data from the format most convenient for the use cases and entities. ● Frameworks and Drivers: This is where all the details go: UI, tools, frameworks, etc.
  • 9. Android architecture The objective is the separation of concerns by keeping the business rules not knowing anything at all about the outside world, thus, they can can be tested without any dependency to any external element. To achieve this, the proposal is about breaking up the project into 3 different layers, in which each one has its own purpose and works separately from the others.
  • 10. Presentation layer Is here, where the logic related with views and animations happens. It uses no more than a Model View Presenter (MVP), but you can use any other pattern like MVC or MVVM. For example, fragments and activities are only views, there is no logic inside them other than UI logic, and this is where all the rendering stuff takes place. Presenters in this layer are composed with interactors (use cases) that perform the job in a new thread outside the android UI thread, and come back using a callback with the data that will be rendered in the view.
  • 11. Domain layer Business rules here: all the logic happens in this layer. Regarding the android project, you will see all the interactors (use cases) implementations here as well. This layer is a pure java module without any android dependencies. All the external components use interfaces when connecting to the business objects.
  • 12. Data layer All data needed for the application comes from this layer through a Repository implementation (the interface is in the domain layer) that uses a Repository Pattern with a strategy that, through a factory, picks different data sources depending on certain conditions. The idea behind all this is that the data origin is transparent for the client, which does not care if the data is coming from memory, disk or the cloud, the only truth is that the data will arrive and will be got.
  • 13. Project structure Presentation module Is the Android application itself, with its resources, assets, logic, etc.
  • 14. Project structure Domain module This module hosts use-cases and their implementations, it is the business logic of the application.
  • 15. Project structure Model module This module is responsible for managing the information, select, save, delete, etc.
  • 16. Communication Now, how we communicate these layers? One approach is communication over an Message Bus system. This system is very useful for Broadcast events, or to establish a communication between components. Basically, events are sent through a Bus and the classes interested to consume that event have to subscribe to that Bus. To implement the system bus, we used the library Otto by Square, but we can use EventBus by GreenRobot too. Both libraries implements the publish/subscribe pattern.
  • 19. Testing We have different solutions for each layer: ● Presentation Layer: Android instrumentation and Espresso for integration and functional testing ● Domain Layer: JUnit plus Mockito for unit tests ● Data Layer: Robolectric (since this layer has android dependencies) plus JUnit plus Mockito for integration and unit tests.
  • 20. Espresso Espresso is a testing framework that exposes a simple API to perform UI testing of Android apps. With the latest 2.0 release, Espresso is now part of the Android Support Repository which makes it more easier to add automated testing support for your project. Key features: ● Its code looks a lot like English, which makes it predictable and easy to learn. ● The API is relatively small, and yet open for customization. ● Espresso tests run optimally fast (no waits, sleeps) ● Gradle + Android Studio support
  • 21. Espresso Is built up from 3 major components: These components are: ● ViewMatchers – allows you to locate a view in the current view hierarchy ● ViewActions – allows you to interact with views ● ViewAssertions – allows you to assert the state of a view. For simplicity, you may use these shortcuts to refer to them: ● ViewMatchers – “find something“ ● ViewActions – “do something“ ● ViewAssertions – “check something“
  • 22. Espresso Here is an example for this:
  • 23. Espresso Here is an example for this:
  • 24. JUnit JUnit in version 4.x is a test framework which uses annotations to identify methods that specify a test.
  • 25. JUnit From Android Studio 1.1, we have fully integration with JUnit.
  • 27. Support Library Design Support Library This library implements some custom views from Material Design such as: NEW
  • 29. Support Library V7 Appcompat Library - IMPORTANT!!! This library adds support from API V7 (Android 2.1) for basic elements: ● Toolbar ● CardView ● GridLayout ● PaletteLibrary ● RecyclerView ● … and more
  • 30. Support Library V4 Support Library This library adds support from API V4 (Android 1.6) for basic elements: ● Fragment ● NotificationCompat ● ViewPager ● PagerTitle ● DrawerLayout ● ... and a lot more
  • 31. Support Library Testing Support Library This library provides an extensive framework for testing Android apps. You can run tests created using these APIs from the Android Studio IDE or from the command line. Includes the following test automation tools: ● AndroidJUnitRunner: JUnit 4-compatible test runner for Android ● Espresso: UI testing framework; suitable for functional UI testing within an app ● UI Automator: UI testing framework; suitable for cross-app functional UI testing across system and installed apps
  • 32. Libraries we can depend on
  • 33. Why libraries? ● Maintained by the community ● Easy to use ● Well documented ● It just works!!! ● Don't reinvent the wheel!!!
  • 34. Retrofit Type-safe REST client for Android and Java by Square, Inc. Retrofit turns your REST API into a Java interface. The RestAdapter class generates an implementation of the GitHubService interface.
  • 35. Retrofit Each call on the generated GitHubService makes an HTTP request to the remote webserver. More examples:
  • 36. Picasso Image transformation Picasso allows for hassle-free image loading in your application — often in one line of code!
  • 37. ButterKnife View injection library Annotate fields with @InjectView and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.
  • 38. Gson Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object.
  • 39. Gson We can customize named fields, this improves code readability:
  • 40. Stetho Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature natively part of the Chrome desktop browser.
  • 41.
  • 42. How? Adding this libraries to our project it's really easy. This libraries are located in two main repositories: ● Maven Central ● JCenter - Default on Android Studio On our build.gradle file, we add:
  • 45. Finding libraries ● RXJava - Reactive Programming ● Dagger2 - Dependency Injection ● Kotlin - New scripting language
  • 46. References ● Robert Martin - The Clean Architecture ● Fernando Cejas - The Clean Architecture ● Gradle - Android Tools ● Android Developers - Support Libraries ● Design Support Library Examples - Repository ● Retrofit - REST Adapter ● Picasso - Image loader ● Gson - JSON parser ● Stetho - View inspector ● Espresso - Samples ● Android Arsenal - For libraries / Gradle Please - Gradle dependencies