WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
Speed up the mobile development process
1. Speed up the
development process
Gianluca Capozzi, Gabriele Cervelli, Giorgio De Magistris, Daniele Davoli
Giuseppe Capaldi, Leonardo Sarra
2. Mobile development: different approaches
One of the most important aspects required by a developer is the speed
with which a mobile application can be developed. There are two main
approaches:
● Native application
● Cross platform application
3. Native application approach
Native apps are developed exclusively for a specific platform. These apps are
developed in a language compatible with the platform (i.e. Swift and Objective-C
for iOS and Java for Android)
● High performance
● Accordance with the
design language
● Usually more scalable
● No limitations when it
comes to using phone
hardware
● Native look and feel for the
UI
● Multiple platforms
require separate
applications
● Higher development
costs
4. Cross-platform approach
Cross-platform apps are compatible with multiple platforms. In order to write
cross-platform applications for mobile devices there are many frameworks (such
as Xamarin and Cordova) and programming languages (Kotlin, JavaScript).
● Faster development
● Lower costs
● Wider audience
● Consistency between
platforms
● No native look and feel when a
common UI is used
● Some frameworks have a big
performance hit
● Some frameworks don’t
expose the latest device APIs
● Knowledge of the underlying
platform is still required
6. What is Kotlin?
- Open-source programming language
developed by JetBrains
- Statically typed
- Runs on top of the JVM,Javascript and LLVM
(Native)
- Officially supported language by Android
since 2017, Android reference language since
May 2019
- Kotlin evolution driven by the Kotlin
Foundation (Google + Jetbrains)
7. Why Kotlin?
● Open-source
● 100% interoperability with Java
● Expressive & concise code with lean syntax
● Enforces null safety
● Easy to learn
● Functional programming features
● Support for MPP (Multi-platform projects)
● Great IDE support (IntelliJ Idea and Android
Studio)
8. Expressive and concise code
● Less boilerplate
● String interpolation
● Default parameter
● Type inference
class Person (val name:String, val surname:String, var age:Int,
val birthCity :String = "Rome")
fun main(args: Array<String>) {
val person = Person(name = "Leonardo", surname = "Sarra", age = 22)
val person2 = Person("Leonardo", "Sarra", 22,"Rome")
println("Name: ${person.name}")
println("Age: ${person.age}")
println("City: ${person.birthCity}")
println("Equals: ${person == person2}") //Returns false (default equals,
//different objects)
}
9. Complete Java Interoperability
public static void main(String []args) {
Person person = new Person("Leonardo","Sarra", 22, "Rome");
System.out.println(String.format("%s %s - %s years old",person.getName(),
person.getSurname(),person.getAge()));
}
class Person (val name:String, val surname:String, var age:Int,
val birthCity :String = "Rome")
fun main(args: Array<String>) {
val person = Person(name = "Leonardo", surname = "Sarra", age = 22)
val person2 = Person("Leonardo", "Sarra", 22,"Rome")
println("Name: ${person.name}")
println("Age: ${person.age}")
println("City: ${person.birthCity}")
println("Equals: ${person == person2}") //Returns false (default equals,
//different objects)
}
10. Less boilerplate: OpenStud as an example
Let’s take as an example the Java Student
class from the OpenStud Android app and
its Kotlin counterpart.
The student object contains all
student-related information and is made
of 23 variables
12. Java way: 280+ lines of code of pure boilerplate
to implement a class that abstracts a student
Kotlin counterpart: data classes
In Kotlin, declaring data class is more
than enough.
Getters, setters, equals, hashcode,
toString are provided by default.
Can be used in Java thanks to the
complete interoperability.
import java.time.LocalDate
data class Student (
val socialSecurityNumber: String,
val firstName: String,
val lastName: String,
val birthCity: String,
val birthPlace: String,
val courseYear: String,
val firstEnrollment: String,
val lastEnrollment: String,
val departmentName: String,
val courseName: String,
val nation: String,
val email: String,
val citizenship: String,
val gender: String,
val studentStatus: String,
val studentID: String,
val birthDate: LocalDate,
val academicYear: Int ,
val academicYearCourse: Int,
val codeCourse: Int,
val typeStudent: Int,
val cfu: Int,
val isErasmus: Boolean)
Student object is made of:
1. Declaration
2. Getter and setters
3. equals, hashcode, toString
(A lot)
13. Safe
- var (mutable) vs val (immutable) variables
- Null safety
fun prettyPrint(student: Person?){
student?.let {
println("Name: ${it.name}")
println("Last name: ${it.surname}")
println("City: ${it.birthCity}")
} ?: println("No person found!")
}
fun prettyPrintAssert(student: Person?) {
student!!.run {
println("Name: $name")
println("Last name: $surname")
println("City: $birthCity")
}
// If student is null, assert is triggered
}
15. Standard collection extensions functions
fun main(args: Array<String>) {
val people = listOf(...)
// print all person name and age
people.forEach { println("Name: ${it.name}, age: ${it.age} years old") }
// all people sorted by age (ascending)
people.sortedBy { it.age }
// first Luigi
people.first { it.gender == "Luigi"}
// oldest Luigi
people.filter {it.gender == "Luigi" }.maxBy { it.age }
// group people by age
people.groupBy { it.age }.maxBy { it.value.count() }
// age 10 years from now
people.map { it.copy(age = it.age + 10) }
// partition people with age below and equal or above 25
people.partition { it.age <= 25}
// each gender count
people.groupingBy { it.gender }.eachCount()
// all people where age below average age
val averageAge = people.map { it.age }.average()
people.filter { it.age <= averageAge }
}
16. What else
● Coroutines
● Delegation
● Inline lambdas
● Reified generics
● Sealed Class (Algebraic Data Type) and Anonymous Class
● Smart casts
● Supports for Reactive Programming (RxKotlin extension)
● And much much more
17. Kotlin Common
● Kotlin common code means that it
relies only on the standard library.
Support for HTTP, serialization, and
management of coroutines is
provided by default.
● Enables support for multi platform
projects
● Kotlin common can be exported to
native code which runs on JVM,
Android, JavaScript, Native(iOS, x86
and even embedded systems like
STM32)
18. Behind the scene of Kotlin Common
Kotlin/JVM Kotlin/JS Kotlin/Native
19. JVM-exclusive project
- Kotlin + JVM environment
- Can be used to create Android apps using the Android
SDK
- Supports Kotlin Android Extensions for extra features and
APIs
- Can use Java artefacts freely
Multiplatform project
- Shared code written in Kotlin common
- Platform specific bits (like UI View) must be written
using native code for that platform (e.g: Java/Kotlin for
Android, Swift/Objective C for iOS).
- Apps will have a native look and feel
20. Kotlin for multiplatform. Why?
- Compilation to native platform-specific executable artefacts
- No bridges between shared code and native platforms
- Faster development
- Best possible performance
- Can easily support platform-specific libraries and solutions
- Perfect for typical apps and for games, native or high performance applications
But...
- Kotlin Multiplatform support is still an experimental feature and things are subject to
changes
- You still need to have a good-enough knowledge of the platforms on which you are
working on to write the platform-dependant bits of your code
- Kotlin/Native is always lagging behind Kotlin/JVM and Kotlin/JS in terms of features
22. Xamarin is...
A framework for app-development that
allows to:
● Write native applications on different
platforms (Android, IOS, MacOS,
Windows Phone)
● Share the same C# codebase
● Use Visual Studio IDE
● Take advantage of all the .NET
libraries
https://docs.microsoft.com/en-us/xamarin/
23. Why Xamarin?
Legacy applications development:
● APIs written in application-specific
language
● Platform-specific features
● Different IDEs
● Application-specific UI and user experience
25. Xamarin.IOS and Xamarin.Android
● 100% coverage of platform-specific APIs with the added benefits of .NET APIs
● Fully native performance
● Shared code for common logic
26. Pros
● Design UI with platform-specific user experience
● Access all platform-specific features (all that you can do in xCode
and Swift or in Java and Android Studio you can do it also with
Xamarin.IOS and Xamarin.Android)
Cons
● Need to have experience with the specific framework APIs and
functionalities
● Cannot share UI logic among different platforms
27. Xamarin.Forms
● Common API for all platform
● Can access most common hardware-specific features (Camera, GPS, Phone Dialer, etc) through
Xamarin.Essential
● Xamarin.Forms creates native controls for each platform at runtime
28. Pros
● Fast deploy of applications among different platforms
● Native applications. Xamarin.Forms APIs are translated into native APIs
● Share markup for user interface
● Can access hardware-specific features using common APIs
● No platform-specific knowledge required
● Good unified documentation
Cons
● Cannot access some very specific platform-specific features
● Cannot personalize UI to look and feel exactly like a platform specific
application
29. Xamarin.Forms project
When we create a new Xamarin.Forms project the solution includes:
● The shared project, containing:
○ All the dependencies (.NET Standard Library, Xamarin.Forms and
Xamarin.Essential)
○ The App.xaml.cs class, that handles the cycle of life of the
application and instantiates the MainPage.xaml.cs class, that’s the
entry point of the application
● The platform-specific projects, each of which references the
shared code and the Xamarin.Forms code
31. MBaaS: what is it?
● Model for providing to mobile app
developers a way to link their
applications to backend cloud
storage and APIs exposed by
backend applications
● The provider (as Microsoft Azure for
example) offers to the developer all
the settings in order to reduce the
time needed to setting up a
customized (and traditional)
backend
32. How services are provided?
● A MBaas usually provides some of this services:
○ User Management
○ Push Notifications
○ Integration with social networking services
○ File Storage
● Services are provided in the following ways:
○ Use of custom Software Development Kit (SDKs)
○ Application Programming Interfaces (APIs)
33. Advantages and disadvantages
● No waste of time: a consistent way to manage backend data implies that developers don't
need to redevelop their own backend for each of the services that they want to access
● Scalability: the developer doesn't have to worry about what's going on the server side
● Analytics: the use of APIs give the access to all the traffic analytics
● Security: most of the BaaS vendors do provide real good security protocols.
Pros
Cons
● Control: developers usually like to have complete control over the source code but most
vendors restrict access to the backend source code.
● Vendor Lock In: the user has to read carefully the terms of use of each vendor and evaluate if
there is a vendor lock in when data migration is necessary.
35. Azure Mobile App Service
● Microsoft MBaaS solution, first
released in March 2015
● Mobile applications built with this
solution easily integrate with other
services provided by Azure (such as
website apps, logic apps, and API
apps)
38. Major Functionalities
● Client SDK support for building native applications on Android, iOS, and Windows devices,
as well as cross-platform applications using the Xamarin framework
● Applications that can work offline and sync data in the background by connecting with APIs
and data sources
● Different options for user authentication and authorization, including integration with social
media platforms (such as Facebook and Twitter)
● Customized push notifications
41. Pros
● High availability: uptime guaranteed is 99.95%
● Good scalability options: you can add or remove instances to your
application whenever you feel the need to
● Optimized for Mobile devices and Tablets: Data and network
optimization for mobile applications, and minimized fragmentation
troubles across multiple devices and platforms.
● Efficiency gains: Reduces the backend system development time &
cost, and the maintenance cost as well
● It allows you to use any framework, language, or tool: Azure allows
you to build apps with the language you prefer, including .NET, Java,
and Node.js
Cons ● Requires Management: it needs to be expertly managed and
maintained, which includes patching and server monitoring
● Requires Platform Expertise: it requires expertise to ensure all
moving parts work together efficiently
● Comparatively expensive
● Speed can be an issue for some businesses
42. ● Google comprehensive mobile development
platform, released in 2011 by Firebase and
acquired by Google in 2014
47. Firebase gives its best by using it in combination
with Google Cloud Platform and some third party
services
Integration with services
48. Pros
● Getting a whole app off the ground is fast – auth, email, versioning, hosting,
monitoring, devops, uptime.
● The data structure is JSON which maps perfectly to UI JavaScript
● Libraries across programming languages are similar and pretty good
● Minimal, or no, knowledge of devops/sysadmin is necessary
● All you need for the backend of a small mobile app
Cons
● Your entire backend is proprietary (BaaS), owned and run by another
company.
● Exceptionally expensive at scale compared to REST
● Migrating off means rewriting all backend tests and much backend
code.
● You must duplicate any business logic across all systems that interact
with firebase.
● Querying and aggregating are limited compared to SQL or popular
NoSQL databases like MongoDB
https://symboliclogic.io/firebase-pros-and-cons/